Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Nov 5, 2025

Follow-on after #14890.

That PR implemented ScopeManager class. Instead of a class, which an instance of is created for each file, use a singleton object, with the underlying TS-ESLint scope manager stored in a top-level var. Methods/getters of SCOPE_MANAGER lazily initialize the TS-ESLint scope manager as required, and cache it.

This pattern is the same as we use for SourceCode, enabled by the fact that only 1 file is linted at a time. This has several advantages:

  1. Reduce object creation - less GC pressure.
  2. Property accesses don't need to go up prototype chain, as they would for instances of a class.
  3. No need for private properties, which are somewhat expensive to access.

Copy link
Member Author

overlookmotel commented Nov 5, 2025


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.

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 refactors the ScopeManager implementation from a class-based approach to a singleton frozen object pattern, improving performance and memory efficiency.

Key Changes:

  • Converted ScopeManager from a class to a frozen singleton object (SCOPE_MANAGER)
  • Moved scope manager state management from source_code.ts to scope.ts for better encapsulation
  • Implemented lazy initialization of the underlying TS-ESLint scope manager

Reviewed Changes

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

File Description
apps/oxlint/src-js/plugins/source_code.ts Updated imports and removed local scope manager state, delegating to the new SCOPE_MANAGER singleton
apps/oxlint/src-js/plugins/scope.ts Refactored ScopeManager class to a frozen singleton object with lazy initialization and added reset functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@overlookmotel overlookmotel force-pushed the 11-05-perf_linter_plugins_use_singleton_object_for_scopemanager_ branch 2 times, most recently from 75a6a13 to 728ea43 Compare November 5, 2025 16:11
@overlookmotel overlookmotel self-assigned this Nov 5, 2025
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Nov 5, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 5, 2025

Merge activity

Follow-on after #14890.

That PR implemented `ScopeManager` class. Instead of a class, which an instance of is created for each file, use a singleton object, with the underlying TS-ESLint scope manager stored in a top-level var. Methods/getters of `SCOPE_MANAGER` lazily initialize the TS-ESLint scope manager as required, and cache it.

This pattern is the same as we use for `SourceCode`, enabled by the fact that only 1 file is linted at a time. This has several advantages:

1. Reduce object creation - less GC pressure.
2. Property accesses don't need to go up prototype chain, as they would for instances of a class.
3. No need for private properties, which are somewhat expensive to access.
@graphite-app graphite-app bot force-pushed the 11-05-perf_linter_plugins_use_singleton_object_for_scopemanager_ branch from 728ea43 to 4c0ba92 Compare November 5, 2025 16:23
@graphite-app graphite-app bot merged commit 4c0ba92 into main Nov 5, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 11-05-perf_linter_plugins_use_singleton_object_for_scopemanager_ branch November 5, 2025 16:30
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 5, 2025
@Boshen Boshen mentioned this pull request Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter 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