Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@TelpeNight
Copy link

This is the fix for #566

It is fairy simple and doesn't compromise performance. All cache operations are backed by atomic.Pointers. On my machine it is as fast as pure implementation. (atomic vs no_race)

goos: darwin
goarch: arm64
pkg: github.com/goccy/go-json/internal/decoder
cpu: Apple M4 Pro
BenchmarkCompileToGetDecoder/no_race-14                 1000000000               0.6914 ns/op
BenchmarkCompileToGetDecoder/race-14                     9604449               127.2 ns/op
BenchmarkCompileToGetDecoder/atomic-14                  1000000000               0.7008 ns/op
PASS
ok      github.com/goccy/go-json/internal/decoder       3.037s
goos: darwin
goarch: arm64
pkg: github.com/goccy/go-json/internal/encoder
cpu: Apple M4 Pro
BenchmarkCompileToGetCodeSet/no_race-14                 1000000000               0.7024 ns/op
BenchmarkCompileToGetCodeSet/race-14                     7301108               163.9 ns/op
BenchmarkCompileToGetCodeSet/sync_map-14                1000000000               1.097 ns/op
BenchmarkCompileToGetCodeSet/atomic-14                  1000000000               0.6981 ns/op
PASS
ok      github.com/goccy/go-json/internal/encoder       4.285s

Test files are for red-flagging current implementation (SHOW_COMPILE_RACE=1 go test -race ./...) and benchmarking. Can be safely removed if needed.

Current state of repo is dangerous, as it allows reading of partially written data. Please merge the fix ASAP.

@TelpeNight TelpeNight changed the title Fix encode/decoder compile data race Fix encode/decoder compile data race https://github.com/goccy/go-json/issues/566 Jan 7, 2026
@TelpeNight TelpeNight changed the title Fix encode/decoder compile data race https://github.com/goccy/go-json/issues/566 Fix encode/decoder compile data race (#566) Jan 7, 2026
@TelpeNight TelpeNight changed the title Fix encode/decoder compile data race (#566) Fix encode/decoder compile data race Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant