Skip to content

Optimize Temurin tool-cache fast path with lazy loading - #1179

Merged
brunoborges merged 4 commits into
mainfrom
brunoborges-optimize-temurin-tool-cache-fast-path
Jul 29, 2026
Merged

Optimize Temurin tool-cache fast path with lazy loading#1179
brunoborges merged 4 commits into
mainfrom
brunoborges-optimize-temurin-tool-cache-fast-path

Conversation

@brunoborges

Copy link
Copy Markdown
Contributor

Description:
This change optimizes the high-volume Temurin tool-cache-hit path by reducing eager startup work and overlapping dependency cache restore with local setup work. It does this by lazy-loading only the selected distribution installer, loading cache dependencies only when cache is configured, and starting restore early while still awaiting completion before action exit.

To preserve behavior and failure semantics, the setup flow now keeps Java/setup failures deterministic while still awaiting any in-flight cache restore to avoid unhandled promise rejections. Tests were updated to cover async distribution resolution, conditional module loading, and true concurrency in orchestration.

The setup bundle was regenerated after introducing dynamic imports. Because the setup output is now chunked, the release staging script was updated to include dist/setup/*.js.

Related issue:
Fixes: #1177

Check list:

  • Ran npm run check locally (format, lint, build, test) and all checks pass.
  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

- Lazy-load distribution installers so only the selected distro module is initialized
- Defer cache feature/cache module loading until cache input is provided
- Start cache restore early and await it safely alongside Java setup flow
- Update orchestration and lazy-loading tests; regenerate dist artifacts

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc2c0256-c55e-4a35-a584-5bed7e8b11ad
Copilot AI review requested due to automatic review settings July 29, 2026 19:58
@brunoborges
brunoborges requested a review from a team as a code owner July 29, 2026 19:58

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 optimizes the common Temurin tool-cache-hit path by reducing eager module initialization and introducing concurrency between dependency cache restoration and local Java setup, while preserving deterministic failure behavior. It also regenerates the bundled dist/ output to support dynamic imports/code-splitting and updates tests to validate lazy loading and true overlap.

Changes:

  • Make distribution selection lazy by converting the distribution factory to async and dynamically importing only the selected installer.
  • Start dependency cache restoration earlier (only when cache is configured) and await it before exit while keeping Java/setup errors deterministic.
  • Add/update unit tests for async distribution resolution, conditional module loading, and concurrent orchestration; regenerate dist/ and update the release staging script.
Show a summary per file
File Description
src/util.ts Removes cache feature detection from the shared util module to avoid eager cache dependency loading.
src/setup-java.ts Orchestrates async distribution resolution and overlaps cache restore with setup; awaits in-flight cache work before exit.
src/distributions/distribution-factory.ts Converts factory to async with per-distribution dynamic imports (lazy loading).
src/cache-feature.ts New module encapsulating cache availability checks (lazy-load target).
package.json Updates release script to stage chunked dist/setup/*.js artifacts.
dist/setup/index.js Rebuilt setup entry bundle to support dynamic imports/code splitting.
dist/setup/978.index.js Generated setup bundle chunk (Zulu installer).
dist/setup/968.index.js Generated setup bundle chunk (GraalVM installers).
dist/setup/939.index.js Generated setup bundle chunk (Semeru installer).
dist/setup/874.index.js Generated setup bundle chunk (Adopt + Temurin installers).
dist/setup/735.index.js Generated setup bundle chunk (OpenJDK installer).
dist/setup/675.index.js Generated setup bundle chunk (Dragonwell installer).
dist/setup/63.index.js Generated setup bundle chunk (Liberica installer).
dist/setup/557.index.js Generated setup bundle chunk (SapMachine installer).
dist/setup/524.index.js Generated setup bundle chunk (Liberica NIK installer).
dist/setup/463.index.js Generated setup bundle chunk (Temurin installer).
dist/setup/394.index.js Generated setup bundle chunk (cache feature detection).
dist/setup/377.index.js Generated setup bundle chunk (cache restore/save implementation).
dist/setup/282.index.js Generated setup bundle chunk (JetBrains installer).
dist/setup/220.index.js Generated setup bundle chunk (Microsoft installer).
dist/setup/182.index.js Generated setup bundle chunk (Oracle installer).
dist/setup/151.index.js Generated setup bundle chunk (Kona installer).
dist/setup/126.index.js Generated setup bundle chunk (Corretto installer).
dist/setup/19.index.js Generated setup bundle chunk (Local/jdkfile installer).
dist/cleanup/index.js Rebuilt cleanup bundle to match new build output.
tests/util.test.ts Removes cache feature tests/mocks from util tests (logic moved).
tests/setup-java.test.ts Updates orchestration tests for async factory + concurrent cache restore and deterministic failure handling.
tests/setup-java.module-loading.test.ts New test ensuring cache modules are not imported when cache input is absent.
tests/distributors/openjdk-installer.test.ts Updates factory registration test to await async factory.
tests/distributors/graalvm-installer.test.ts Updates factory mapping test(s) to await async factory.
tests/distributors/distribution-factory.test.ts Updates all factory tests to async/await and rejects assertions.
tests/distributors/distribution-factory.lazy-loading.test.ts New test to ensure non-selected installers aren’t imported on Temurin path.
tests/cache-feature.test.ts New dedicated tests for cache feature detection behavior.

Review details

Tip

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

  • Files reviewed: 13/35 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread src/setup-java.ts
Comment thread package.json Outdated
brunoborges and others added 3 commits July 29, 2026 16:06
- Lazy-load cache save in cleanup path so no-cache runs avoid cache module init in post action
- Stage dist/setup/package.json in release script for chunked setup bundle completeness

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc2c0256-c55e-4a35-a584-5bed7e8b11ad
Patch is-unsafe's XML comment-close detector during builds so generated bundles recognize both HTML comment end forms and satisfy CodeQL until the dependency publishes a fix.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 277302b1-aa95-4012-817b-9752cdaee14e
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc2c0256-c55e-4a35-a584-5bed7e8b11ad
@brunoborges
brunoborges merged commit 3cc3643 into main Jul 29, 2026
88 checks passed
@brunoborges
brunoborges deleted the brunoborges-optimize-temurin-tool-cache-fast-path branch July 29, 2026 21:53
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.

Optimize the Temurin tool-cache fast path

2 participants