Skip to content

Conversation

@SyMind
Copy link
Member

@SyMind SyMind commented Oct 31, 2025

This PR optimizes memory usage by changing the internal representation of source content from String to Arc<str> throughout the codebase. This enables efficient string sharing and reduces allocations when the same source content is referenced multiple times.

Key Changes:

  • Changed SourceMap::sources_content from Arc<[String]> to Arc<[Arc<str>]>
  • Updated OriginalSource::value and SourceMapSource::original_source to use Arc<str> instead of String
  • Introduced SourceContentLines struct using the self_cell crate to manage self-referential data structures for cached line splitting
@SyMind SyMind force-pushed the perf-soruces-content branch from 94fcfda to 957c493 Compare October 31, 2025 06:37
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 31, 2025

CodSpeed Performance Report

Merging #196 will improve performances by 13.1%

Comparing perf-soruces-content (dd0f92a) with main (c4f7e16)

Summary

⚡ 1 improvement
✅ 10 untouched
⏩ 5 skipped1

Benchmarks breakdown

Benchmark BASE HEAD Change
stringify_source_map_to_json 16.6 ms 14.7 ms +13.1%

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@SyMind SyMind force-pushed the perf-soruces-content branch from 9f5b1c8 to e99ef2b Compare October 31, 2025 07:10
@SyMind SyMind force-pushed the perf-soruces-content branch from e99ef2b to dd0f92a Compare October 31, 2025 07:17
@SyMind SyMind marked this pull request as ready for review October 31, 2025 07:18
Copilot AI review requested due to automatic review settings October 31, 2025 07:18
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 memory usage by changing the internal representation of source content from String to Arc<str> throughout the codebase. This enables efficient string sharing and reduces allocations when the same source content is referenced multiple times.

Key Changes:

  • Changed SourceMap::sources_content from Arc<[String]> to Arc<[Arc<str>]>
  • Updated OriginalSource::value and SourceMapSource::original_source to use Arc<str> instead of String
  • Introduced SourceContentLines struct using the self_cell crate to manage self-referential data structures for cached line splitting

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/source_map_source.rs Updated original_source field type and simplified string conversions using .into()
src/source_content_lines.rs Added new struct for efficiently managing source content split into lines with self-referential ownership
src/source.rs Changed sources_content to use Arc<[Arc<str>]> and updated related methods
src/replace_source.rs Refactored SourceContent enum and helper functions to work with Arc<str> and SourceContentLines
src/original_source.rs Changed value field to Arc<str> and updated OnSource callback signature
src/lib.rs Added module declaration for source_content_lines
src/helpers.rs Updated helper functions, type signatures, and removed unused code
benches/bench.rs Updated test data initialization to use .into() conversion
Cargo.toml Added self_cell dependency
Cargo.lock Added self_cell package entry

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SyMind SyMind merged commit 98db0a7 into main Oct 31, 2025
16 checks passed
@SyMind SyMind deleted the perf-soruces-content branch October 31, 2025 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants