Skip to content

Make SourceFileAffectingCompilerOptions hold fully computed values, use in binder #788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Apr 10, 2025

This PR makes SourceFileAffectingCompilerOptions consist of only fully computed values (in prep for some other changes).

  • We can now prove that the binder (and in the future, parser) only touch things that they need.
  • The values can be computed once and reused.
  • SourceFileAffectingCompilerOptions is smaller, allowing much more AST reuse.

The AST reuse results in the tests running 20-25% faster, and using 1GB less peak memory.

psrecord before:

old

psrecord after:

new

Before, it's maybe 8GB, before maybe 7GB.

@jakebailey jakebailey changed the title Compute SourceFileAffectingCompilerOptions and use in binder Make SourceFileAffectingCompilerOptions hold fully computed values, use in binder Apr 10, 2025
Copy link
Contributor

@Copilot 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.

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

AllowUnusedLabels: options.AllowUnusedLabels,
PreserveConstEnums: options.PreserveConstEnums,
IsolatedModules: options.IsolatedModules,
func (options *CompilerOptions) SourceFileAffecting() *SourceFileAffectingCompilerOptions {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is not cached anywhere since we'd have to put it on CompilerOptions, which means sync.Once, which means no more DeepEqual.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
AllowUnusedLabels: options.AllowUnusedLabels,
PreserveConstEnums: options.PreserveConstEnums,
IsolatedModules: options.IsolatedModules,
func (options *CompilerOptions) SourceFileAffecting() *SourceFileAffectingCompilerOptions {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if this should continue to be a value type or not, since we pass it around and so on. But it's not that large, actually.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tested and it keeping it a value doesn't actually hurt or help perf, so I could do that.

@@ -1331,7 +1331,7 @@ func (b *Binder) checkStrictModeWithStatement(node *ast.Node) {

func (b *Binder) checkStrictModeLabeledStatement(node *ast.Node) {
// Grammar checking for labeledStatement
if b.inStrictMode && b.options.Target >= core.ScriptTargetES2015 {
if b.inStrictMode && b.options.EmitScriptTarget >= core.ScriptTargetES2015 {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a porting bug I'm fixing, FWIW.

@jakebailey jakebailey added this pull request to the merge queue Apr 10, 2025
Merged via the queue into main with commit 36be503 Apr 10, 2025
23 checks passed
@jakebailey jakebailey deleted the jabaile/computed-source-affecting-options branch April 10, 2025 17:59
shinichy pushed a commit to shinichy/typescript-go that referenced this pull request Apr 12, 2025
…se in binder (microsoft#788)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants