Skip to content

Comments

perf(minifier): use oxc_data_structures::stack::Stack for ClassSymbolsStack#14029

Merged
graphite-app[bot] merged 1 commit intomainfrom
09-23-perf_minifier_use_oxc_data_structures_stack_stack_for_classsymbolsstack
Sep 24, 2025
Merged

perf(minifier): use oxc_data_structures::stack::Stack for ClassSymbolsStack#14029
graphite-app[bot] merged 1 commit intomainfrom
09-23-perf_minifier_use_oxc_data_structures_stack_stack_for_classsymbolsstack

Conversation

@sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Sep 23, 2025

Changed ClassSymbolsStack to Stack from normal Vec.

Copy link
Member Author

sapphi-red commented Sep 23, 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 A-minifier Area - Minifier C-performance Category - Solution not expected to change functional behavior, only performance labels Sep 23, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 23, 2025

CodSpeed Instrumentation Performance Report

Merging #14029 will not alter performance

Comparing 09-23-perf_minifier_use_oxc_data_structures_stack_stack_for_classsymbolsstack (c0ef5f3) with main (a05cb23)1

Summary

✅ 37 untouched

Footnotes

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

@sapphi-red sapphi-red force-pushed the 09-23-perf_minifier_use_oxc_data_structures_stack_stack_for_classsymbolsstack branch from a1476b3 to 57f5fd6 Compare September 23, 2025 05:50
@sapphi-red sapphi-red force-pushed the 09-23-feat_data_structures_add_stack_clear_ branch from c5758c6 to 3c3cdb2 Compare September 23, 2025 05:50
@sapphi-red sapphi-red marked this pull request as ready for review September 23, 2025 06:37
@sapphi-red sapphi-red requested a review from Boshen September 23, 2025 06:39
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.

I don't think the clear call should be required. From what I can see, the stack is filled and then emptied again during traversal, so it should be always be empty by exit_program anyway (and therefore still empty in the next enter_program call).

The pattern we generally use with stacks in transformer is:

struct SomeTransform {
  stack: Stack<ThingName>,
}

impl<'a> Traverse<'a> for SomeTransform {
  fn enter_program(&mut self, program: &mut Program, ctx: &mut TraverseCtx<'a>) {
    // Nothing to do. `stack` is always empty here.
  }

  fn enter_thing(&mut self, thing: &mut Thing<'a>, ctx: &mut TraverseCtx<'a> {
    self.stack.push(thing.name);
  }

  fn exit_thing(&mut self, thing: &mut Thing<'a>, ctx: &mut TraverseCtx<'a> {
    self.stack.pop().unwrap();
    // Or, if logic is simple enough that it's clear
    // there's no possibility of mismatched push-pop calls
    // unsafe { self.stack.pop_unchecked() };
  }

  #[inline] // Because it's a noop in release mode
  fn exit_program(&mut self, program: &mut Program, ctx: &mut TraverseCtx<'a>) {
    debug_assert!(self.stack.is_empty());
  }
}

This debug_assert! approach has the advantage of making sure that every push is followed by a corresponding pop, and the stack doesn't get out of sync with traversal.


You may find that oxc_data_structures::stack::NonEmptyStack is cheaper than Stack. That has really cheap last and last_mut methods. Downside is you have to provide a dummy first entry when creating the NonEmptyStack, but if MinifierState is being used over and over, that's a 1-off cost.


Feel free not to take these suggestions into account. Just wanted to let you know the patterns we've found work well with the stack types, in case it's useful.

@sapphi-red
Copy link
Member Author

Ah, true, clear isn't required! I saw Stack being used somewhere else and thought it might work here too. Thanks for the comment!

@sapphi-red sapphi-red changed the base branch from 09-23-feat_data_structures_add_stack_clear_ to graphite-base/14029 September 23, 2025 13:19
@sapphi-red sapphi-red force-pushed the 09-23-perf_minifier_use_oxc_data_structures_stack_stack_for_classsymbolsstack branch from 57f5fd6 to ac9e89b Compare September 23, 2025 13:20
@sapphi-red sapphi-red changed the base branch from graphite-base/14029 to 09-22-feat_mangler_mangle_private_class_members September 23, 2025 13:20
@sapphi-red sapphi-red force-pushed the 09-23-perf_minifier_use_oxc_data_structures_stack_stack_for_classsymbolsstack branch from ac9e89b to a1091e9 Compare September 23, 2025 13:22
@sapphi-red
Copy link
Member Author

Changed to NonEmptyStack 👍 Because the benchmark doesn't contain any class decls/exprs, it doesn't have any affect there. But I guess this change won't hurt anything.

@sapphi-red sapphi-red force-pushed the 09-22-feat_mangler_mangle_private_class_members branch from 5f62088 to 8274783 Compare September 23, 2025 13:26
@sapphi-red sapphi-red force-pushed the 09-23-perf_minifier_use_oxc_data_structures_stack_stack_for_classsymbolsstack branch from a1091e9 to 4906b11 Compare September 23, 2025 13:26
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Sep 24, 2025
Copy link
Member

Boshen commented Sep 24, 2025

Merge activity

…sStack (#14029)

Changed `ClassSymbolsStack` to `Stack` from normal `Vec`.
@graphite-app graphite-app bot force-pushed the 09-22-feat_mangler_mangle_private_class_members branch from 8274783 to 0fe4d95 Compare September 24, 2025 03:35
@graphite-app graphite-app bot force-pushed the 09-23-perf_minifier_use_oxc_data_structures_stack_stack_for_classsymbolsstack branch from 4906b11 to c0ef5f3 Compare September 24, 2025 03:35
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 24, 2025
Base automatically changed from 09-22-feat_mangler_mangle_private_class_members to main September 24, 2025 03:41
@graphite-app graphite-app bot merged commit c0ef5f3 into main Sep 24, 2025
28 checks passed
@graphite-app graphite-app bot deleted the 09-23-perf_minifier_use_oxc_data_structures_stack_stack_for_classsymbolsstack branch September 24, 2025 03:42
graphite-app bot pushed a commit that referenced this pull request Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier 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.

3 participants