Skip to content

perf: reduce string allocation in sourcemap encoding#163

Merged
Boshen merged 1 commit intomainfrom
09-23-perf_reduce_string_allocation_in_sourcemap_encoding
Sep 24, 2025
Merged

perf: reduce string allocation in sourcemap encoding#163
Boshen merged 1 commit intomainfrom
09-23-perf_reduce_string_allocation_in_sourcemap_encoding

Conversation

@Brooooooklyn
Copy link
Member

@Brooooooklyn Brooooooklyn commented Sep 23, 2025

Only allocate once in fn to_json_string

@Brooooooklyn Brooooooklyn marked this pull request as draft September 23, 2025 15:42
Copy link
Member Author


How to use the Graphite Merge Queue

Add 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-hq
Copy link

codspeed-hq bot commented Sep 23, 2025

CodSpeed Performance Report

Merging #163 will degrade performances by 2.25%

Comparing 09-23-perf_reduce_string_allocation_in_sourcemap_encoding (17d9e9b) with main (5f9c22d)

Summary

⚡ 2 improvements
❌ 2 regressions
✅ 1 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
from_json_string 16.8 µs 16.6 µs +1.05%
generate_lookup_table 1.3 µs 1.3 µs -2.25%
to_json 5.5 µs 5.7 µs -2.2%
to_json_string 6.8 µs 5.4 µs +26.93%

@Brooooooklyn Brooooooklyn marked this pull request as ready for review September 23, 2025 15:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_string to use direct string writes via escape_into functions instead of Cow<str> wrappers
  • Simplifies PreAllocatedString to use a single String buffer instead of a vector of string segments
  • Improves serialize_sourcemap_mappings to 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.

@Brooooooklyn Brooooooklyn marked this pull request as draft September 23, 2025 16:19
@Brooooooklyn Brooooooklyn force-pushed the 09-23-perf_reduce_string_allocation_in_sourcemap_encoding branch from 05e8517 to 17d9e9b Compare September 24, 2025 02:16
@Brooooooklyn Brooooooklyn marked this pull request as ready for review September 24, 2025 02:19
@Boshen Boshen merged commit 29f716c into main Sep 24, 2025
7 checks passed
@Boshen Boshen deleted the 09-23-perf_reduce_string_allocation_in_sourcemap_encoding branch September 24, 2025 02:52
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.

3 participants