Skip to content

Conversation

@camchenry
Copy link
Member

No description provided.

Copy link
Member Author

camchenry commented May 31, 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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label May 31, 2025
@camchenry camchenry force-pushed the 05-30-refactor_mangler_use_bump_allocator_for_internal_storage branch from ef0fae9 to 6d377a2 Compare May 31, 2025 03:55
@codspeed-hq
Copy link

codspeed-hq bot commented May 31, 2025

CodSpeed Instrumentation Performance Report

Merging #11409 will improve performances by 3.27%

Comparing 05-30-refactor_mangler_use_bump_allocator_for_internal_storage (bfa05f2) with 05-30-refactor_mangler_use_external_allocator (fa4966d)

Summary

⚡ 1 improvements
✅ 37 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[RadixUIAdoptionSection.jsx] 14.8 µs 14.3 µs +3.27%

Copy link
Member

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

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

mangler[RadixUIAdoptionSection.jsx] 15.1 µs 14.2 µs +6.57%

Nice! I am guessing that this isn't just noise. RadixUIAdoptionSection.jsx is the smallest test fixture, so it makes sense it moves the needle most here, as the allocations are a larger slice of the overall workload. Personally I think it's the most important benchmark we have as it's most representative of real-world code. Most people don't write 50,000-line files like checker.ts!

It's a shame that FixedBitset doesn't support custom allocators, or we could put them into the temp arena too. They're ideal candidates for putting in an arena as they never grow (high cost of growth is the only perf downside of arena-allocated data structures).

Probably we could write our own version of FixedBitset which allocates in an arena. We don't use most of FixedBitset's APIs, and I don't think the APIs we do use benefit from SIMD-acceleration, so our version could be a lot simpler. That could be fun! But, to be honest, mangler is so fast anyway that it's not the first place we should be looking for optimizations.

@camchenry camchenry force-pushed the 05-30-refactor_mangler_use_external_allocator branch 2 times, most recently from 4f9be98 to 5cf8bc8 Compare June 8, 2025 02:08
@camchenry camchenry force-pushed the 05-30-refactor_mangler_use_bump_allocator_for_internal_storage branch 2 times, most recently from 5b87703 to b85605f Compare June 8, 2025 02:19
@camchenry
Copy link
Member Author

camchenry commented Jun 8, 2025

It's a shame that FixedBitset doesn't support custom allocators, or we could put them into the temp arena too. They're ideal candidates for putting in an arena as they never grow (high cost of growth is the only perf downside of arena-allocated data structures).

We could at least put this into an arena-owned Vec if our Vec implementation supported resize_with by the way: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.resize_with. The mangler is currently using this method with the FixedBitSet Vec. I didn't want to implement it in this PR stack but that's a future improvement we can make here as well.

@camchenry camchenry marked this pull request as ready for review June 8, 2025 02:21
@camchenry
Copy link
Member Author

Perf improvement appears to be fairly consistent after refactoring as well:

⚡ mangler[RadixUIAdoptionSection.jsx] 15 µs 14.2 µs +5.59%

@overlookmotel
Copy link
Member

overlookmotel commented Jun 8, 2025

We could at least put this into an arena-owned Vec if our Vec implementation supported resize_with

I don't think we can, unfortunately. oxc_allocator::Vec does not allow storing types which own heap memory (are Drop), because Vec does nothing on drop. So it'd leak memory if it contained types which rely on drop being called to free the memory they own. This is by design - it makes dropping an AST very fast. But consequently, putting FixedBitSets in arena would require a new impl which stores its data in arena, instead of on the heap, so it doesn't require Drop.

That said, we should implement Vec::resize_with. I'm not sure why we don't have it.

@camchenry camchenry force-pushed the 05-30-refactor_mangler_use_external_allocator branch from 5cf8bc8 to 723308b Compare June 8, 2025 22:35
@camchenry camchenry force-pushed the 05-30-refactor_mangler_use_bump_allocator_for_internal_storage branch from b85605f to 37b6c55 Compare June 8, 2025 22:35
@camchenry
Copy link
Member Author

I don't think we can, unfortunately. oxc_allocator::Vec does not allow storing types which own heap memory (are Drop), because Vec does nothing on drop. So it'd leak memory if it contained types which rely on drop being called to free the memory they own. This is by design - it makes dropping an AST very fast. But consequently, putting FixedBitSets in arena would require a new impl which stores its data in arena, instead of on the heap, so it doesn't require Drop.

Makes sense, I thought it was simply the lack of FixedBitSet::with_capacity_in or a similar function, thanks for the explanation.

@camchenry camchenry added the 0-merge Merge with Graphite Merge Queue label Jun 8, 2025
Copy link
Member Author

camchenry commented Jun 8, 2025

Merge activity

@camchenry camchenry force-pushed the 05-30-refactor_mangler_use_external_allocator branch from 723308b to ba6c24b Compare June 8, 2025 22:39
@camchenry camchenry force-pushed the 05-30-refactor_mangler_use_bump_allocator_for_internal_storage branch from 37b6c55 to d97fe8d Compare June 8, 2025 22:39
@graphite-app graphite-app bot force-pushed the 05-30-refactor_mangler_use_external_allocator branch from ba6c24b to fa4966d Compare June 8, 2025 22:50
@graphite-app graphite-app bot force-pushed the 05-30-refactor_mangler_use_bump_allocator_for_internal_storage branch from d97fe8d to bfa05f2 Compare June 8, 2025 22:51
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jun 8, 2025
Base automatically changed from 05-30-refactor_mangler_use_external_allocator to main June 8, 2025 22:57
@graphite-app graphite-app bot merged commit bfa05f2 into main Jun 8, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 05-30-refactor_mangler_use_bump_allocator_for_internal_storage branch June 8, 2025 22:58
Boshen pushed a commit that referenced this pull request Jul 7, 2025
Related to #11347.

Mangler benchmarks display so much variance that they're pretty useless.
Valiant attempts to reduce the variance (#11408, #11409) have not
worked, and contributors have been getting confused by the bonkers
"Performance regressed 13%" alerts on unrelated PRs.

No one is working on mangler at the moment, so just disable the damn
things!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants