Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 4, 2025

We currently store the default keyword for ExportDefaultDeclaration as a ModuleExportName. This is overkill because the name is always, by definition, default.

Replace this field with default_span: Span which is enough to provides the only useful information.

This reduces size of ExportDefaultDeclaration from 80 bytes to 32. That has very limited impact, because each file can only have 1 export default statement. But still... less is more!

Ideally we'd get rid of this field entirely. Span of default keyword doesn't appear in ESTree AST, is not used in linter, and is ignored in codegen.

Only reason this span is present in AST is: parser records it temporarily in AST, so that ModuleRecordBuilder can pull it out again later to add it to module record. There is probably a way to achieve the same thing without using AST as a temporary storage location.

UPDATE: I found a way to remove the field entirely: #12808.

@github-actions github-actions bot added A-parser Area - Parser A-ast Area - AST A-transformer Area - Transformer / Transpiler A-isolated-declarations Isolated Declarations A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Aug 4, 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 4, 2025

CodSpeed Instrumentation Performance Report

Merging #12803 will not alter performance

Comparing 08-01-refactor_ast_replace_exportdefaultdeclaration_exported_field_with_default_span_ (9ceca68) with main (5475075)

Summary

✅ 34 untouched benchmarks

@overlookmotel overlookmotel force-pushed the 08-01-refactor_ast_replace_exportdefaultdeclaration_exported_field_with_default_span_ branch from 4af75b4 to 9ceca68 Compare August 4, 2025 12:24
@github-actions github-actions bot added the A-semantic Area - Semantic label Aug 4, 2025
@overlookmotel overlookmotel marked this pull request as ready for review August 4, 2025 12:27
@overlookmotel overlookmotel requested a review from Dunqing as a code owner August 4, 2025 12:27
@overlookmotel overlookmotel marked this pull request as draft August 4, 2025 13:58
graphite-app bot pushed a commit that referenced this pull request Aug 5, 2025
…12808)

We currently store the `default` keyword for `ExportDefaultDeclaration` as a `ModuleExportName`. This is overkill because the name is always, by definition, `default`.

The only place the `Span` of `default` keyword is used is in `ModuleRecordBuilder`. So essentially storing the span in AST is using the AST as temporary storage - it's only put there so that `ModuleRecordBuilder` can pull it out again.

After #12807, we can just pass the span direct to `ModuleRecordBuilder`, and so remove the need for it to be in the AST at all.

So we can remove the whole field.

This reduces size of `ExportDefaultDeclaration` from 80 bytes to 24. That has very limited impact, because each file can only have 1 `export default` statement. But still... less is more!

It also removes erroneous code in both isolated declarations and transformer, which both just gave the keyword an empty span. I think the fact that everywhere that does use this field uses it wrongly is good justification for its removal!

(alternative to #12803)
@overlookmotel
Copy link
Member Author

Superceded by #12808.

@overlookmotel overlookmotel deleted the 08-01-refactor_ast_replace_exportdefaultdeclaration_exported_field_with_default_span_ branch August 8, 2025 10:00
taearls pushed a commit to taearls/oxc that referenced this pull request Aug 12, 2025
…xc-project#12808)

We currently store the `default` keyword for `ExportDefaultDeclaration` as a `ModuleExportName`. This is overkill because the name is always, by definition, `default`.

The only place the `Span` of `default` keyword is used is in `ModuleRecordBuilder`. So essentially storing the span in AST is using the AST as temporary storage - it's only put there so that `ModuleRecordBuilder` can pull it out again.

After oxc-project#12807, we can just pass the span direct to `ModuleRecordBuilder`, and so remove the need for it to be in the AST at all.

So we can remove the whole field.

This reduces size of `ExportDefaultDeclaration` from 80 bytes to 24. That has very limited impact, because each file can only have 1 `export default` statement. But still... less is more!

It also removes erroneous code in both isolated declarations and transformer, which both just gave the keyword an empty span. I think the fact that everywhere that does use this field uses it wrongly is good justification for its removal!

(alternative to oxc-project#12803)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-formatter Area - Formatter A-isolated-declarations Isolated Declarations A-parser Area - Parser A-semantic Area - Semantic A-transformer Area - Transformer / Transpiler 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