perf(tegg-loader): dedupe concurrent module loads#6035
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to prevent duplicate concurrent module loading in ModuleLoader by caching and sharing the in-flight loading promise (loadPromise). It also ensures that if a load fails, the promise is cleared so that subsequent retries can be attempted. Corresponding unit tests have been added to verify concurrent sharing and retry behavior. There are no review comments, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Deploying egg with
|
| Latest commit: |
e6cecbb
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a4d96efb.egg-cci.pages.dev |
| Branch Preview URL: | https://codex-tegg-loader-concurrent.egg-cci.pages.dev |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesModule loading
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant CallerA
participant CallerB
participant ModuleLoader
participant LoaderUtil
CallerA->>ModuleLoader: load()
ModuleLoader->>LoaderUtil: loadFile()
CallerB->>ModuleLoader: load()
ModuleLoader-->>CallerB: existing loadPromise
LoaderUtil-->>ModuleLoader: loaded module data
ModuleLoader-->>CallerA: loaded classes
ModuleLoader-->>CallerB: loaded classes
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #6035 +/- ##
=======================================
Coverage 82.18% 82.18%
=======================================
Files 678 678
Lines 20844 20853 +9
Branches 4156 4158 +2
=======================================
+ Hits 17130 17138 +8
- Misses 3206 3207 +1
Partials 508 508 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR improves the tegg core ModuleLoader by deduplicating concurrent load() calls: concurrent callers now share a single in-flight load promise, and the in-flight state is cleared on completion so failures remain retryable. This fits the loader’s existing caching model (completed results cached via protoClazzList) while avoiding duplicate filesystem/import work during startup races.
Changes:
- Add an in-flight
loadPromisetoModuleLoader.load()to share work across concurrent callers. - Ensure
loadPromiseis cleared in afinallyblock so retries after failure work as before. - Add regression tests covering concurrent deduplication and retry-after-failure behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tegg/core/loader/src/impl/ModuleLoader.ts | Share an in-flight loadOnce() promise across concurrent load() calls and clear it after completion. |
| tegg/core/loader/test/ModuleLoaderManifest.test.ts | Add tests for concurrent in-flight deduplication and retry behavior after a failed load. |
Deploying egg-v3 with
|
| Latest commit: |
e6cecbb
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a91a2584.egg-v3.pages.dev |
| Branch Preview URL: | https://codex-tegg-loader-concurrent.egg-v3.pages.dev |
Performance dataI ran the same warmed microbenchmark against the parent commit (
Benchmark core: for (let i = 0; i < 200; i++) {
const loader = new ModuleLoader(moduleDir, {
precomputedFiles: ['AppRepo.ts', 'SprintRepo.ts', 'UserRepo.ts'],
});
await Promise.all(Array.from({ length: 16 }, () => loader.load()));
}Command: utx tsx /tmp/tegg-loader-inflight-bench.ts <egg-root> 200 16 5This intentionally isolates the concurrent in-flight path. End-to-end application boot improvement depends on how often startup paths overlap on the same |
Summary
ModuleLoader.load()promise between concurrent callersMotivation
protoClazzListonly caches completed loads. When multiple startup paths callload()before the first call finishes, each caller performs the same file loading and module imports. Keeping a per-loader in-flight promise avoids duplicate work while preserving the existing completed-result cache.Test
Summary by CodeRabbit
Bug Fixes
Tests