Enable json v2 support for 59% faster sourcemap parsing#20
Merged
vmihailenco merged 1 commit intoOct 1, 2025
Merged
Conversation
ba9cb68 to
af36f5d
Compare
Add experimental json/v2 decoder support via build tags for improved performance while maintaining full backward compatibility. - Add unmarshalJSON abstraction in consumer.go - Create json_decoder.go for standard encoding/json (default) - Create json_decoder_v2.go with jsonv2 build tag for Go 1.25+ - Bonus: Minor optimization using strings.Builder for URL concatenation Users can opt-in to json/v2 with: GOEXPERIMENT=jsonv2 go build -tags=jsonv2 ./... This provides ~59% faster parsing with zero API changes.
af36f5d to
e217b05
Compare
Member
|
Looks good, thanks 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for the experimental
encoding/json/v2package through build tags, providing significant performance improvements for sourcemap parsing while maintaining full backward compatibility.Changes
unmarshalJSON()abstraction layer to switch between JSON implementationsjson_decoder.gofor standardencoding/json(default)json_decoder_v2.gowithjsonv2build tag for Go 1.25+json.Unmarshalcalls with the abstraction inconsumer.gostrings.Builderfor more efficient URL concatenationPerformance Improvements
Benchmarks show 50-74% faster parsing across different sourcemap sizes:
Key Metrics
Usage
The change is opt-in and requires no code changes from users:
Benchmarks
I have comprehensive benchmarks that demonstrate these improvements across various sourcemap sizes (from 5KB to 10MB). If you're interested, I can submit them as a follow-up/preamble PR. The benchmarks include:
Why This Matters
Many modern web applications produce large sourcemaps (2-20MB is common), and parsing performance directly impacts:
This simple change provides substantial performance improvements with zero risk to existing users.
References