Skip to content

feat(scope-manager): only call Object.entries once for each lib #10647

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

Conversation

dmichon-msft
Copy link
Contributor

PR Checklist

Overview

Improves performance of populateGlobalsFromLib by ensuring that the referenced lib objects have their Object.entries arrays precomputed. Also saves on garbage collection since each object only ever has a single array of variable specifications.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @dmichon-msft!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 1210cad
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/67c4f4929f3bf7000801d25a
😎 Deploy Preview https://deploy-preview-10647--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 95 (🔴 down 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (🟢 up 8 from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

nx-cloud bot commented Jan 13, 2025

View your CI Pipeline Execution ↗ for commit 1210cad.

Command Status Duration Result
nx run-many --target=build --exclude website --... ✅ Succeeded 36s View ↗
nx run-many --target=build --parallel --exclude... ✅ Succeeded <1s View ↗
nx run-many --target=clean ✅ Succeeded 12s View ↗

☁️ Nx Cloud last updated this comment at 2025-03-03 00:50:59 UTC

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!
Let's just go one step further here and remove the need for any runtime calls to Object.entries.
We can just generate all of the lib files as an array of arrays so that there's no calls at all!

Same with the barrel file -- we can generate the map contents as an array of arrays.

@dmichon-msft
Copy link
Contributor Author

Since you gave me license to restructure the objects from the individual lib files, I went ahead and separated out the concept of "references to other libs" from individual variable definitions, so that in the (unfortunately rather common) case that developers have specified their lib array in such a way that a given lib is included multiple times, we only iterate the variables from it once (per source file, still).

@bradzacher
Copy link
Member

I'm happy to go with a bigger refactor of how all of this works.
We should be able to mitigate the cost of loading libs and the cost of defining variables using this approach which is nice.

Just need to get the tests passing and we can move forward with this!

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party enhancement New feature or request labels Feb 25, 2025
@dmichon-msft
Copy link
Contributor Author

I can rebase/merge this to reconcile the changes to exports that happened a bit back, I just hadn't since the guidance was to leave that to maintainers.

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.44%. Comparing base (9674629) to head (1210cad).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10647   +/-   ##
=======================================
  Coverage   87.44%   87.44%           
=======================================
  Files         469      469           
  Lines       16047    16053    +6     
  Branches     4649     4650    +1     
=======================================
+ Hits        14032    14038    +6     
  Misses       1658     1658           
  Partials      357      357           
Flag Coverage Δ
unittest 87.44% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ackages/scope-manager/src/lib/decorators.legacy.ts 100.00% <100.00%> (ø)
packages/scope-manager/src/lib/decorators.ts 100.00% <100.00%> (ø)
...ackages/scope-manager/src/lib/dom.asynciterable.ts 100.00% <100.00%> (ø)
packages/scope-manager/src/lib/dom.iterable.ts 100.00% <100.00%> (ø)
packages/scope-manager/src/lib/dom.ts 100.00% <ø> (ø)
...ackages/scope-manager/src/lib/es2015.collection.ts 100.00% <100.00%> (ø)
packages/scope-manager/src/lib/es2015.core.ts 100.00% <100.00%> (ø)
packages/scope-manager/src/lib/es2015.generator.ts 100.00% <100.00%> (ø)
packages/scope-manager/src/lib/es2015.iterable.ts 100.00% <100.00%> (ø)
packages/scope-manager/src/lib/es2015.promise.ts 100.00% <100.00%> (ø)
... and 100 more

@bradzacher
Copy link
Member

thanks heaps for this!

@bradzacher bradzacher merged commit 355e892 into typescript-eslint:main Mar 3, 2025
63 checks passed
@JoshuaKGoldberg
Copy link
Member

Before this change, running https://github.com/typescript-eslint/performance:

┌───────┬───────────────────────┬───────────────────────┐
│ files │ project (even layout) │ service (even layout) │
├───────┼───────────────────────┼───────────────────────┤
│ 1024  │ '2.760 s ±  0.006 s'  │ '3.125 s ±  0.011 s'  │
└───────┴───────────────────────┴───────────────────────┘

After:

┌───────┬───────────────────────┬───────────────────────┐
│ files │ project (even layout) │ service (even layout) │
├───────┼───────────────────────┼───────────────────────┤
│ 1024  │ '2.478 s ±  0.022 s'  │ '2.829 s ±  0.020 s'  │
└───────┴───────────────────────┴───────────────────────┘

Nice 🔥

@dmichon-msft dmichon-msft deleted the object-entries-cache branch March 5, 2025 00:02
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

⚡️ Performance: Overhead of populateGlobalsFromLib in scope-manager
3 participants