perf(csvpp,csvpputil): cache reflection type info and optimize YAML encoding#11
Merged
perf(csvpp,csvpputil): cache reflection type info and optimize YAML encoding#11
Conversation
- Add type_cache.go with sync.Map-based per-type cache (encoding/json pattern) - Eliminate per-record tag scanning in encodeRecord by using cached field mappings - Replace buildHeaders/buildFieldMap with cache lookups - Add 100-record Marshal/Unmarshal benchmarks Marshal: -35% latency, -17% allocs, -4% memory (3 records) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add encodeYAMLRecords for direct slice construction in MarshalYAML/WriteYAML - Add WithYAMLCapacity option for pre-allocating internal buffer - Add YAMLArrayWriterOption type following JSONArrayWriterOption pattern Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
sync.Map) in Marshal/Unmarshal followingencoding/jsonpatternWithYAMLCapacityoption for pre-allocating internal bufferChanges
csvpppackage (reflection cache)type_cache.go:typeInfostruct withsync.Mapcache keyed byreflect.Typemarshal.go: RefactorbuildFieldMap,encodeRecord,MarshalWriterto use cached type info. Remove redundantbuildHeadersexport_test.go: ExportCachedTypeInfofor testingbenchmark_test.go: Add 100-record Marshal/Unmarshal benchmarkscsvpputilpackage (YAML optimization)yaml_array_writer.go: AddYAMLArrayWriterOption,WithYAMLCapacity, andencodeYAMLRecordsfor direct batch encoding inMarshalYAML/WriteYAMLyaml_array_writer_test.go: Add capacity hint testsbenchmark_test.go: AddWriteWithCapacitybenchmarkBenchmark Results
Marshal/Unmarshal (reflection cache)
YAML batch encoding
Test Plan
GOEXPERIMENT=jsonv2 go test -race ./...all passbenchstat🤖 Generated with Claude Code