Skip to content

perf(ast_tools): use StructsAndEnums iterator where possible#20944

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/04-01-perf_ast_tools_use_structsandenums_iterator_where_possible
Apr 1, 2026
Merged

perf(ast_tools): use StructsAndEnums iterator where possible#20944
graphite-app[bot] merged 1 commit intomainfrom
om/04-01-perf_ast_tools_use_structsandenums_iterator_where_possible

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Apr 1, 2026

Similar to #20944. In loops where a generator is only interested in structs and enums, use the StructsAndEnums iterator which exits early, rather than pointlessly continuing iterating over all types.

Copy link
Copy Markdown
Member Author

overlookmotel commented Apr 1, 2026


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 changes, fast-track this PR to the front of the merge queue

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-ast-tools Area - AST tools C-performance Category - Solution not expected to change functional behavior, only performance labels Apr 1, 2026
@overlookmotel overlookmotel marked this pull request as ready for review April 1, 2026 18:06
Copilot AI review requested due to automatic review settings April 1, 2026 18:06
@overlookmotel overlookmotel self-assigned this Apr 1, 2026
Copy link
Copy Markdown
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 improves ast_tools generator performance by switching several generator loops from iterating over all Schema::types to using the existing Schema::structs_and_enums() iterator, which stops once non-struct/enum types begin (avoiding needless iteration over container/primitive defs).

Changes:

  • Add TypeDef::as_struct_or_enum() to convert a TypeDef reference into a StructOrEnum (when applicable).
  • Update TypeScript and traverse-related generators to iterate via schema.structs_and_enums() and accept StructOrEnum where appropriate.
  • Narrow traversal “is AST type with visitor” checks to operate on StructOrEnum, updating call sites accordingly.

Reviewed changes

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

Show a summary per file
File Description
tasks/ast_tools/src/schema/defs/type.rs Adds as_struct_or_enum() helper to bridge &TypeDefStructOrEnum when needed.
tasks/ast_tools/src/generators/typescript.rs Uses schema.structs_and_enums() and updates TS type-def generation to take StructOrEnum.
tasks/ast_tools/src/generators/traverse/walk.rs Iterates only structs/enums for walk generation; matches on StructOrEnum.
tasks/ast_tools/src/generators/traverse/mod.rs Iterates only structs/enums for trait method generation; matches on StructOrEnum.
tasks/ast_tools/src/generators/traverse/ancestor.rs Narrows is_ast_type_with_visitor to StructOrEnum and adapts field visitation logic via as_struct_or_enum().
tasks/ast_tools/src/generators/assert_layouts.rs Iterates only structs/enums for layout assertion generation; signature updated to StructOrEnum.

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Apr 1, 2026
Copy link
Copy Markdown
Member Author

overlookmotel commented Apr 1, 2026

Merge activity

Similar to #20944. In loops where a generator is only interested in structs and enums, use the `StructsAndEnums` iterator which exits early, rather than pointlessly continuing iterating over all types.
@graphite-app graphite-app Bot force-pushed the om/04-01-perf_ast_tools_introduce_structs_iterator_and_use_it_where_possible branch from aa93f79 to 91098c4 Compare April 1, 2026 18:14
@graphite-app graphite-app Bot force-pushed the om/04-01-perf_ast_tools_use_structsandenums_iterator_where_possible branch from 12570cf to 3656b5c Compare April 1, 2026 18:15
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Apr 1, 2026
Base automatically changed from om/04-01-perf_ast_tools_introduce_structs_iterator_and_use_it_where_possible to main April 1, 2026 18:21
@graphite-app graphite-app Bot merged commit 3656b5c into main Apr 1, 2026
25 checks passed
@graphite-app graphite-app Bot deleted the om/04-01-perf_ast_tools_use_structsandenums_iterator_where_possible branch April 1, 2026 18:24
graphite-app Bot pushed a commit that referenced this pull request Apr 23, 2026
…e possible (#21686)

Similar to #20944. In loops where a generator is only interested in structs only, or structs and enums, use the `Structs` / `StructsAndEnums` iterators which exit early, rather than pointlessly continuing iterating over all types.

Does not alter generated code, only the means by which it's generated.
graphite-app Bot pushed a commit that referenced this pull request Apr 23, 2026
…e possible (#21686)

Similar to #20944. In loops where a generator is only interested in structs only, or structs and enums, use the `Structs` / `StructsAndEnums` iterators which exit early, rather than pointlessly continuing iterating over all types.

Does not alter generated code, only the means by which it's generated.
graphite-app Bot pushed a commit that referenced this pull request Apr 23, 2026
…e possible (#21686)

Similar to #20944. In loops where a generator is only interested in structs only, or structs and enums, use the `Structs` / `StructsAndEnums` iterators which exit early, rather than pointlessly continuing iterating over all types.

Does not alter generated code, only the means by which it's generated.
graphite-app Bot pushed a commit that referenced this pull request Apr 23, 2026
…e possible (#21686)

Similar to #20944. In loops where a generator is only interested in structs only, or structs and enums, use the `Structs` / `StructsAndEnums` iterators which exit early, rather than pointlessly continuing iterating over all types.

Does not alter generated code, only the means by which it's generated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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