Skip to content

perf(tegg-loader): dedupe concurrent module loads#6035

Merged
elrrrrrrr merged 2 commits into
nextfrom
codex/tegg-loader-concurrent-dedupe
Jul 13, 2026
Merged

perf(tegg-loader): dedupe concurrent module loads#6035
elrrrrrrr merged 2 commits into
nextfrom
codex/tegg-loader-concurrent-dedupe

Conversation

@elrrrrrrr

@elrrrrrrr elrrrrrrr commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • share an in-flight ModuleLoader.load() promise between concurrent callers
  • clear the in-flight promise after completion so failed loads remain retryable
  • add regression coverage for concurrent deduplication and retry-after-failure

Motivation

protoClazzList only caches completed loads. When multiple startup paths call load() 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

utx vitest run tegg/core/loader/test/ModuleLoaderManifest.test.ts
6 tests passed

Summary by CodeRabbit

  • Bug Fixes

    • Improved module loading so simultaneous requests share one in-progress operation, preventing duplicate loading work.
    • Module loading now retries correctly after a failed attempt.
  • Tests

    • Added coverage for concurrent loading and retry behavior.
    • Improved test isolation by restoring mocks after each test.

Copilot AI review requested due to automatic review settings July 13, 2026 08:13

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploying egg with  Cloudflare Pages  Cloudflare Pages

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

View logs

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bad3066f-6802-4e2d-9db0-8a3fb9b5a035

📥 Commits

Reviewing files that changed from the base of the PR and between d0558dc and 886a980.

📒 Files selected for processing (2)
  • tegg/core/loader/src/impl/ModuleLoader.ts
  • tegg/core/loader/test/ModuleLoaderManifest.test.ts

📝 Walkthrough

Walkthrough

ModuleLoader now shares an in-flight loading promise across concurrent calls, clears it after completion or failure, and retries failed loads. Tests cover concurrent deduplication and failure recovery.

Changes

Module loading

Layer / File(s) Summary
In-flight load deduplication and retry validation
tegg/core/loader/src/impl/ModuleLoader.ts, tegg/core/loader/test/ModuleLoaderManifest.test.ts
ModuleLoader caches concurrent loads through loadPromise and loadOnce(), safely resets the cache, restores mocks between tests, and validates single-load concurrency plus retry-after-failure behavior.

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
Loading

Possibly related PRs

Suggested reviewers: jerryliang64

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: deduping concurrent module loads for the tegg loader.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/tegg-loader-concurrent-dedupe

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.18%. Comparing base (d0558dc) to head (e6cecbb).
⚠️ Report is 1 commits behind head on next.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 loadPromise to ModuleLoader.load() to share work across concurrent callers.
  • Ensure loadPromise is cleared in a finally block 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.

@elrrrrrrr
elrrrrrrr requested a review from killagu July 13, 2026 08:17
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 13, 2026

Copy link
Copy Markdown

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

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

View logs

@elrrrrrrr
elrrrrrrr requested a review from gxkl July 13, 2026 08:18

@gxkl gxkl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@elrrrrrrr

Copy link
Copy Markdown
Contributor Author

Performance data

I ran the same warmed microbenchmark against the parent commit (dfd102cc) and this PR (886a980f). Each round creates 200 loaders for the existing 3-file fixture and calls load() 16 times concurrently on each loader. Results are the median of 5 rounds.

Metric per round Before This PR Change
LoaderUtil.loadFile() calls 9,600 600 -93.75% (16x -> 1x work)
Wall time 217.51 ms 44.58 ms -79.5% / 4.88x faster
Process CPU time 294.15 ms 65.03 ms -77.9% / 4.52x lower

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 5

This intentionally isolates the concurrent in-flight path. End-to-end application boot improvement depends on how often startup paths overlap on the same ModuleLoader; the deterministic result here is that duplicate file loads scale from concurrency × files down to files.

@elrrrrrrr
elrrrrrrr enabled auto-merge July 13, 2026 08:30
@elrrrrrrr
elrrrrrrr added this pull request to the merge queue Jul 13, 2026
Merged via the queue into next with commit fc071c2 Jul 13, 2026
27 checks passed
@elrrrrrrr
elrrrrrrr deleted the codex/tegg-loader-concurrent-dedupe branch July 13, 2026 09:01
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.

3 participants