Skip to content

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Aug 13, 2025

No description provided.

@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 13, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-codegen Area - Code Generation C-performance Category - Solution not expected to change functional behavior, only performance labels Aug 13, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 13, 2025

CodSpeed Instrumentation Performance Report

Merging #13054 will not alter performance

Comparing 08-13-perf_codegen_reduce_memory_allocations_in_generate_line_offset_tables_ (ab685bd) with main (8486d8d)1

Summary

✅ 34 untouched benchmarks

Footnotes

  1. No successful run was found on main (ab685bd) during the generation of this report, so 8486d8d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Boshen Boshen marked this pull request as ready for review August 13, 2025 10:11
Copilot AI review requested due to automatic review settings August 13, 2025 10:11
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Aug 13, 2025
Copy link
Member Author

Boshen commented Aug 13, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 08-13-perf_codegen_reduce_memory_allocations_in_generate_line_offset_tables_ branch from 13cb5f5 to ab685bd Compare August 13, 2025 10:12
@graphite-app graphite-app bot merged commit ab685bd into main Aug 13, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 08-13-perf_codegen_reduce_memory_allocations_in_generate_line_offset_tables_ branch August 13, 2025 10:17
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 13, 2025
graphite-app bot pushed a commit that referenced this pull request Aug 13, 2025
…fset_tables` (#13056)

#13054 added a nice optimization to `SourcemapBuilder`. During generation of line/offset tables, it reuses a single `Vec` for column indexes for each line, rather than creating a new `Vec` on each turn of the inner loop. This reduces the number of times that `Vec` may have to grow as column indexes get added to it.

Take this optimization a step further by re-using the same `Vec` across *all* lines.

`columns` `Vec` is not consumed on each line, but each time the contents are copied into a boxed slice - except when reaching EOF, where we can consume `columns`, as its work is done.

This memory-copying was likely happening anyway, as `Vec<u32>` -> `Box<[u32]>` conversion has to drop the spare capacity of the `Vec`, which will likely cause a reallocation.

Also, avoid using iterators to create the boxed slices. `Vec::clone` followed by `Vec::into_boxed_slice` is a bit more explicit and so may help compiler to see that it only needs to allocate exactly `columns.len()` slots for the `Box<[u32]>`.

Note: I also tried `columns.drain(..).collect()` instead of `columns.clone().into_boxed_slice()` + `columns.clear()`. But it looks like the `Drain` abstraction doesn't get completely removed by compiler. https://godbolt.org/z/Trv47j4hP So I *think* `into_boxed_slice` is probably preferable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-codegen Area - Code Generation C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants