Skip to content

perf(ast): use bitflags for storing comment newline state#11096

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-17-perf_ast_use_bitflags_for_storing_newline_state
May 17, 2025
Merged

perf(ast): use bitflags for storing comment newline state#11096
graphite-app[bot] merged 1 commit intomainfrom
05-17-perf_ast_use_bitflags_for_storing_newline_state

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented May 17, 2025

This switches the newline flags to using bitflags to make the setting of the flags a little bit simpler and also makes checking the flag state easier too. Rather than using all flags in a bitflags, this is simpler because we don't need a custom serializer for comments for ESTree.

@github-actions github-actions bot added A-parser Area - Parser A-ast Area - AST C-performance Category - Solution not expected to change functional behavior, only performance labels May 17, 2025
Copy link
Member Author


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.

@camchenry camchenry marked this pull request as ready for review May 17, 2025 16:34
@camchenry camchenry changed the title perf(ast): use bitflags for storing newline state perf(ast): use bitflags for storing comment newline state May 17, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented May 17, 2025

CodSpeed Instrumentation Performance Report

Merging #11096 will not alter performance

Comparing 05-17-perf_ast_use_bitflags_for_storing_newline_state (6571b9b) with main (bcc923c)

Summary

✅ 36 untouched benchmarks

Copy link
Contributor

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 replaces the custom CommentNewlines enum with a bitflags-based struct for simpler flag manipulation and updates all usages to the new constants.

  • Introduces bitflags for CommentNewlines in crates/oxc_ast/src/ast/comment.rs
  • Rewrites newline setter/getter logic to use insert/remove/contains
  • Updates test fixtures in crates/oxc_parser/src/lexer/trivia_builder.rs to reference new flag names

Reviewed Changes

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

File Description
crates/oxc_ast/src/ast/comment.rs Replaced enum with bitflags for newline state and updated related impls
crates/oxc_parser/src/lexer/trivia_builder.rs Updated expected comment newlines in tests to use new CommentNewlines constants

@camchenry camchenry force-pushed the 05-17-perf_ast_use_bitflags_for_storing_newline_state branch from 1105ff9 to 3f90352 Compare May 17, 2025 16:55
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.

Great. Thank you for persisting, despite my misdirection (twice!)

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label May 17, 2025
Copy link
Member

overlookmotel commented May 17, 2025

Merge activity

- supersedes #11090

This switches the newline flags to using `bitflags` to make the setting of the flags a little bit simpler and also makes checking the flag state easier too. Rather than using all flags in a bitflags, this is simpler because we don't need a custom serializer for comments for ESTree.
@graphite-app graphite-app bot force-pushed the 05-17-perf_ast_use_bitflags_for_storing_newline_state branch from 3f90352 to 6571b9b Compare May 17, 2025 23:43
@graphite-app graphite-app bot merged commit 6571b9b into main May 17, 2025
20 of 26 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 17, 2025
@graphite-app graphite-app bot deleted the 05-17-perf_ast_use_bitflags_for_storing_newline_state branch May 17, 2025 23:49
graphite-app bot pushed a commit that referenced this pull request May 19, 2025
Follow-on after #11096. Add `#[inline]` to these trivial functions. Usually they're called with a static value, so if they're inlined compiler will be able to remove the branch.

Probably compiler would inline these anyway as they're so small, but just to make sure.
graphite-app bot pushed a commit that referenced this pull request May 19, 2025
Follow-on after #11096. Pure refactor. Our naming convention for `bitflags!` fields is not completely consistent, but mostly we use mixed case. Rename them to match that style.

Also, remove the `LEADING_AND_TRAILING` option, as it's only used in tests.
graphite-app bot pushed a commit that referenced this pull request May 19, 2025
Follow-on after #11096. Pure refactor. Shorten the setter methods. Also move them to after the getters and in same order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-parser Area - Parser 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