perf: reduce string allocation in sourcemap encoding#163
Conversation
How to use the Graphite Merge QueueAdd the label merge to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #163 will degrade performances by 2.25%Comparing Summary
Benchmarks breakdown
|
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes sourcemap JSON serialization by reducing string allocations in the encoding process. The refactoring replaces multiple Cow<str> allocations with direct string operations.
- Refactors
encode_to_stringto use direct string writes viaescape_intofunctions instead ofCow<str>wrappers - Simplifies
PreAllocatedStringto use a singleStringbuffer instead of a vector of string segments - Improves
serialize_sourcemap_mappingsto write directly into the output buffer
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/encode.rs | Comprehensive refactoring of string allocation patterns to reduce memory overhead in JSON encoding |
| CHANGELOG.md | Fixes typo from "optimzed" to "optimized" |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
05e8517 to
17d9e9b
Compare

Only allocate once in fn
to_json_string