structured-merge-diff icon indicating copy to clipboard operation
structured-merge-diff copied to clipboard

reconsider use of json-iterator / reflect2

Open liggitt opened this issue 3 years ago • 14 comments

The approach taken by json-iterator and its reflect library is not long-term stable (it pins to internal details of the stdlib reflect package), and requires maintenance per go release, which does not appear to be sustainable https://github.com/golang/go/issues/48238#issuecomment-917000973

Minimum versions to work with go1.18+ are:

  • github.com/json-iterator/go v1.1.12
  • github.com/modern-go/reflect2 v1.0.2

In addition to the maintenance aspect, it is hard to reason about the safety of the implementation (https://github.com/golang/go/issues/48238#issuecomment-916331048)

I'm exploring what it would look like to use the stdlib json decoder as a base and add in the features we rely on (case-sensitive keys, preservation of ints/floats, etc) in https://github.com/kubernetes/kubernetes/pull/105030

I would encourage this project to consider the long-term sustainability/safety of the json-iterator dependency as well.

liggitt avatar Sep 14 '21 22:09 liggitt

I think the uses here are benchmarked and it should be easy to tell if swapping out json-iterator causes a regression.

lavalamp avatar Sep 15 '21 20:09 lavalamp

https://github.com/kubernetes/kubernetes/pull/105030 is now merged and this is on the short-list of things in k/k that still use json-iterator

liggitt avatar Oct 22 '21 17:10 liggitt

it looks like this uses really specialized serializing capabilities provided by json-iterator... not sure swapping will be easy

liggitt avatar Oct 22 '21 18:10 liggitt

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jan 20 '22 20:01 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Feb 19 '22 20:02 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

k8s-triage-robot avatar Mar 21 '22 20:03 k8s-triage-robot

@k8s-triage-robot: Closing this issue.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Mar 21 '22 20:03 k8s-ci-robot

/reopen /lifecycle frozen

liggitt avatar Mar 30 '22 15:03 liggitt

@liggitt: Reopened this issue.

In response to this:

/reopen /lifecycle frozen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Mar 30 '22 15:03 k8s-ci-robot

with the release of go1.18, the json-iterator / reflect2 versions this lib uses as of today will not work with current versions of go

liggitt avatar Mar 30 '22 15:03 liggitt

When json-next-experimental becomes non-experimental, we could consider this. I don't think we need to solve this right now though.

apelisse avatar Oct 06 '22 16:10 apelisse

I would still consider use of json-iterator a risk due to its history with correctness issues and reliance on specific internal implementations of the go runtime

liggitt avatar Oct 10 '22 12:10 liggitt

There is more trouble that reflect2 brings. It inhibits the dead code elimination in the golang compiler.

Golang 1.22 has learned to keep the DCE enabled when the usages of MethodByName() are limited to MethodByName(compile-time constant). Usages of MethodByName() in github.com/kubernetes/kubernetes are DCE-friendly already, and various dependencies like google.golang.org/protobuf and github.com/kubernetes/kube-openapi were fixed to be DCE-friendly over several last months.

reflect2 plays tricks that confuse golang and disable the DCE. Everything that depends on structured-merge-diff, even indirectly, compiles with the DCE disabled because of reflect2.

dominiquelefevre avatar Jan 03 '24 16:01 dominiquelefevre

@liggitt I created a first working version: https://github.com/kubernetes-sigs/structured-merge-diff/pull/257

inteon avatar Apr 11 '24 16:04 inteon