Skip to content

perf: avoid double Arc allocation in add_source_and_content#288

Merged
Boshen merged 1 commit intomainfrom
fix/avoid-double-arc-in-add-source-and-content
Mar 20, 2026
Merged

perf: avoid double Arc allocation in add_source_and_content#288
Boshen merged 1 commit intomainfrom
fix/avoid-double-arc-in-add-source-and-content

Conversation

@Boshen
Copy link
Copy Markdown
Member

@Boshen Boshen commented Mar 20, 2026

Summary

  • add_source_and_content previously created two Arc<str> allocations when a new source was added — one via entry(source.into()) and another via self.sources.push(source.into()).
  • Use get first to avoid any allocation on the duplicate-hit path, then create a single Arc and clone it for the map — matching the pattern already used in add_name.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 20, 2026

Merging this PR will degrade performance by 4.64%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 4 improved benchmarks
❌ 3 regressed benchmarks
✅ 6 untouched benchmarks
⏩ 5 skipped benchmarks1

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

Performance Changes

Benchmark BASE HEAD Efficiency
build_single 6.5 µs 6.4 µs +1.73%
add_sourcemap_loop 20.9 µs 20.1 µs +4.13%
serialize[real_small] 4.2 µs 4.4 µs -4.62%
serialize[real_large] 20.1 µs 20.3 µs -1.01%
lookup_table[real_small] 1.4 µs 1.4 µs +2.13%
lookup_table[real_medium] 1.5 µs 1.5 µs +1.97%
serialize[real_medium] 4.8 µs 5 µs -4.64%

Comparing fix/avoid-double-arc-in-add-source-and-content (6797349) with main (59d8044)2

Open in CodSpeed

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.

  2. No successful run was found on main (1548e7b) during the generation of this report, so 59d8044 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Boshen Boshen merged commit b7fe1cf into main Mar 20, 2026
7 checks passed
@Boshen Boshen deleted the fix/avoid-double-arc-in-add-source-and-content branch March 20, 2026 12:38
@Boshen Boshen mentioned this pull request Mar 20, 2026
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.

1 participant