-
-
Notifications
You must be signed in to change notification settings - Fork 0
perf(move-file): cache index file export analysis #316
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
Draft
LayZeeDK
wants to merge
4
commits into
main
Choose a base branch
from
feat/161-index-exports-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ff7458e
perf(move-file): cache index file export analysis (#161)
LayZeeDK d0358cd
chore: address review feedback (index exports cache)
LayZeeDK a188b59
refactor(move-file): clean up cache invalidation for index exports
LayZeeDK 6908df5
fix(move-file): address review feedback on index export cache separation
LayZeeDK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| ÔùÅ Validation Warning: | ||
|
|
||
| Unknown option "reporters" with value ["default"] was found. | ||
| This is probably a typing mistake. Fixing it will remove this message. | ||
|
|
||
| Configuration Documentation: | ||
| https://jestjs.io/docs/configuration | ||
|
|
||
| console.log | ||
| [Export Management > Export detection] should detect exports x 56,768 ops/sec ┬▒2.09% (48553 runs sampled) | ||
|
|
||
| at Object.<anonymous> (tools/tinybench-utils.ts:1323:17) | ||
|
|
||
| console.log | ||
| [Export Management > Export addition] should add exports x 61,458 ops/sec ┬▒1.81% (54844 runs sampled) | ||
|
|
||
| at Object.<anonymous> (tools/tinybench-utils.ts:1323:17) | ||
|
|
||
| console.log | ||
| [Export Management > Export removal] should remove exports x 56,077 ops/sec ┬▒1.82% (50026 runs sampled) | ||
|
|
||
| at Object.<anonymous> (tools/tinybench-utils.ts:1323:17) | ||
|
|
||
| PASS benchmarks packages/workspace/src/generators/move-file/benchmarks/export-management.bench.ts | ||
| Export Management | ||
| Export detection | ||
|  should detect exports (25 ms) | ||
| Export addition | ||
|  should add exports (1 ms) | ||
| Export removal | ||
|  should remove exports | ||
|
|
||
| Test Suites: 1 passed, 1 total | ||
| Tests: 3 passed, 3 total | ||
| Snapshots: 0 total | ||
| Time: 4.658 s, estimated 5 s | ||
| Ran all test suites matching /export-management/i. |
62 changes: 62 additions & 0 deletions
62
packages/workspace/src/generators/move-file/export-management/index-exports-cache.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import type { Tree } from '@nx/devkit'; | ||
| import { treeReadCache } from '../tree-cache'; | ||
|
|
||
| /** | ||
| * Cached export information for index (entrypoint) files to avoid reparsing. | ||
| */ | ||
| export interface IndexExports { | ||
| exports: Set<string>; // direct exports (file paths without extension) | ||
| reexports: Set<string>; // re-exported modules (file paths without extension) | ||
| } | ||
|
|
||
| interface CachedIndexExports extends IndexExports { | ||
| content: string; // content snapshot used to build this cache entry | ||
| } | ||
|
|
||
| // Internal cache keyed by normalized index file path | ||
| const indexExportsCache = new Map<string, CachedIndexExports>(); | ||
|
|
||
| /** Clears all cached index export data. */ | ||
| export function clearIndexExportsCache(): void { | ||
| indexExportsCache.clear(); | ||
| } | ||
|
|
||
| /** Invalidates a single index file from the cache (e.g., after write). */ | ||
| export function invalidateIndexExportsCacheEntry(indexPath: string): void { | ||
| indexExportsCache.delete(indexPath); | ||
| } | ||
|
|
||
| /** | ||
| * Get (and cache) export info for an index/entrypoint file. | ||
| * Lightweight regex based extraction – sufficient for current export patterns. | ||
| */ | ||
| export function getIndexExports(tree: Tree, indexPath: string): IndexExports { | ||
| const content = treeReadCache.read(tree, indexPath, 'utf-8') || ''; | ||
|
|
||
| const cached = indexExportsCache.get(indexPath); | ||
| if (cached && cached.content === content) return cached; | ||
|
|
||
| const exports = new Set<string>(); // local exports (currently none parsed) | ||
| const reexports = new Set<string>(); // export ... from / export * from specifiers | ||
|
|
||
| // Match: export * from './path'; OR export { ... } from './path'; OR export {default as X} from './path'; | ||
| const reExportPattern = | ||
| /export\s+(?:\*|\{[^}]+\})\s+from\s+['"](\.\.?\/[^'";]+)['"];?/g; | ||
| // Match: export * from './path'; specially capture star exports for potential future distinction | ||
| // Simple capture group for path without extension processing here | ||
|
|
||
| let match: RegExpExecArray | null; | ||
| while ((match = reExportPattern.exec(content))) { | ||
| const spec = match[1]; | ||
| reexports.add(spec); | ||
| } | ||
|
|
||
| // Note: We do NOT add reexports to the exports set to avoid conflating concepts. | ||
| // exports holds normalized local export specifiers (if/when we add direct export collection logic). | ||
| // For current patterns (only re-exports), exports remains empty; callers may consult reexports directly. | ||
| // Future enhancement: parse local declarations (e.g. export { foo, bar }; without 'from'). | ||
|
|
||
| const result: CachedIndexExports = { exports, reexports, content }; | ||
| indexExportsCache.set(indexPath, result); | ||
| return result; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| ÔùÅ Validation Warning: | ||
|
|
||
| Unknown option "reporters" with value ["default"] was found. | ||
| This is probably a typing mistake. Fixing it will remove this message. | ||
|
|
||
| Configuration Documentation: | ||
| https://jestjs.io/docs/configuration | ||
|
|
||
| console.log | ||
| [Export Management > Export detection] should detect exports x 62,156 ops/sec ┬▒1.66% (55877 runs sampled) | ||
|
|
||
| at Object.<anonymous> (tools/tinybench-utils.ts:1323:17) | ||
|
|
||
| console.log | ||
| [Export Management > Export addition] should add exports x 61,446 ops/sec ┬▒1.30% (54407 runs sampled) | ||
|
|
||
| at Object.<anonymous> (tools/tinybench-utils.ts:1323:17) | ||
|
|
||
| console.log | ||
| [Export Management > Export removal] should remove exports x 62,213 ops/sec ┬▒4.02% (56818 runs sampled) | ||
|
|
||
| at Object.<anonymous> (tools/tinybench-utils.ts:1323:17) | ||
|
|
||
| PASS benchmarks packages/workspace/src/generators/move-file/benchmarks/export-management.bench.ts | ||
| Export Management | ||
| Export detection | ||
|  should detect exports (13 ms) | ||
| Export addition | ||
|  should add exports (1 ms) | ||
| Export removal | ||
|  should remove exports (1 ms) | ||
|
|
||
| Test Suites: 1 passed, 1 total | ||
| Tests: 3 passed, 3 total | ||
| Snapshots: 0 total | ||
| Time: 4.375 s, estimated 5 s | ||
| Ran all test suites matching /export-management/i. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern allows paths that don't start with './' or '../' by using
\.\.?\/which makes the second dot optional. This could match invalid paths like./xincorrectly. The pattern should be(\.\.?\/[^'";]+)or more specifically(\.(?:\.\/|\/)[^'";]+)to properly match relative paths.