Skip to content

Speed up server startup class loading and module extraction - #1562

Merged
labkey-jeckels merged 8 commits into
developfrom
fb_faster_startup
Nov 25, 2026
Merged

labkey-jeckels merged 8 commits into
developfrom
fb_faster_startup

Conversation

@labkey-jeckels

@labkey-jeckels labkey-jeckels commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Rationale

This PR shortens server startup by cutting time spent in class loading and module extraction, part of getting TeamCity BVT suites to their first test sooner. Measured speedups for each change are in the PR comments. Deploys still rewrite every module archive, so the first restart after a deploy still checks every module; that build-side cause is https://github.com/LabKey/internal-issues/issues/1936.

Related Pull Requests

Changes

  • When the webapp supplies no classes of its own, answer Tomcat's class-loader lookups without touching the disk
  • When a module archive changes, rewrite only the files whose content changed instead of deleting and re-extracting the whole module
  • Extract the largest module archives first so a big one can't start last and stretch the extraction phase

@labkey-jeckels

Copy link
Copy Markdown
Contributor Author

Speedup: skipping the WEB-INF/classes probe

Three alternating before/after pairs of routine restarts on a local dev server (macOS), same build:

Before After
Spring "Started in" 13.5 s (14.2 / 13.3 / 13.0) 12.1 s (11.7 / 12.7 / 12.0)
JVM start → module startup complete 21.3 s (21.9 / 21.5 / 20.4) 19.3 s (18.7 / 19.9 / 19.2)

Each missed probe costs about 90 µs (File.getCanonicalPath on a missing path), and about 33,000 classes load during startup. Linux agents probably see a smaller gain.

@labkey-jeckels

Copy link
Copy Markdown
Contributor Author

Speedup: incremental module extraction

Four alternating before/after pairs of restarts right after a deploy on a local dev server (macOS, 189 modules). Every deploy rewrites every .module today, since the buildTime in config/module.xml changes on each build:

Before After
Module extraction ("Exploding module archives" → complete) 7.98 s avg (6.75 / 6.82 / 7.62 / 10.73) 2.55 s avg (1.79 / 2.24 / 3.44 / 2.71)
Spring "Started in", first two pairs 18.3 s (17.1 / 19.5) 12.3 s (11.8 / 12.7)

About 5.4 s saved per post-deploy restart. Extraction used to delete each exploded module and rewrite all ~17,000 files whenever an archive's timestamp changed. It now keeps files whose size and CRC match the archive and removes only what the archive no longer contains, so the remaining time is mostly reading existing files to check their CRCs. The last two pairs ran under heavy machine load, so their startup totals are left out. Restarts without a deploy are unaffected, and TeamCity, which always extracts into an empty directory, sees no gain.

@labkey-jeckels

Copy link
Copy Markdown
Contributor Author

Speedup: largest-first module extraction

Six alternating before/after pairs of full extractions (all 189 modules into empty directories, as on a fresh install or TeamCity agent), running ModuleExtractor.extractModules() on a local dev machine (macOS):

Before After
Full module extraction 4.50 s avg (5.42 / 4.54 / 4.39 / 4.19 / 4.31 / 4.14) 4.03 s avg (4.27 / 3.93 / 3.86 / 4.16 / 3.97 / 3.98)

About 0.5 s saved, and the ordered run was faster in all six pairs. Archives used to be split across the common pool in directory order, so a large one (jbrowse, assistant, onprc_ehr each take 2–4 s alone) could start last and stretch the whole phase. They're now queued by estimated cost (uncompressed bytes plus a per-file charge, which together fit per-module extraction times with r² = 0.97) and handed out largest first. A heavy background disk load inflated the absolute times for both variants. Restarts that only re-extract a few changed modules see no difference.

@labkey-jeckels labkey-jeckels changed the title Skip Tomcat's WEB-INF/classes probe on every class load Speed up server startup class loading and module extraction Nov 20, 2026
@labkey-jeckels
labkey-jeckels marked this pull request as ready for review November 22, 2026 20:29
@labkey-jeckels labkey-jeckels self-assigned this Nov 22, 2026
List<File> undeleted = new ArrayList<>();
ExplodedModule.deleteDirectory(targetDirectory, false, undeleted);
Set<File> unreplaced = new LinkedHashSet<>(undeleted);
// Rewrite only entries whose content changed; every build rewrites module.xml, so most entries are unchanged

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.

I don't follow the final conclusion in this comment. Maybe reword?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reworded.

// Rewrite only entries whose content changed; a rebuilt module is re-extracted over the last one, and most files are usually unchanged

{
private static final String WEB_INF_CLASSES = "/WEB-INF/classes";

private volatile boolean _noWebappClasses = false;

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.

Why isn't this always true? Is this just future-proofing in case some class ends up in /WEB-INF/classes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. More complicated than it needed to be. I simplified.

@labkey-jeckels
labkey-jeckels merged commit 9493c66 into develop Nov 25, 2026
8 checks passed
@labkey-jeckels
labkey-jeckels deleted the fb_faster_startup branch November 25, 2026 00:45
labkey-jeckels added a commit to LabKey/platform that referenced this pull request Nov 25, 2026
## Rationale
This PR shortens server bootstrap and routine startup, part of getting
TeamCity BVT suites to their first test sooner. Measured speedups for
each change are in the PR comments.

## Related Pull Requests
- LabKey/server#1562

## Changes
- Load PostgreSQL foreign-key metadata with a lighter per-table catalog
query instead of the JDBC driver's
- Check for missing database views by name rather than by loading full
table metadata
- Skip the view check and the encryption cipher migration on a new
install
- Initialize audit providers in parallel

## Testing
New `JdbcMetaDataTest` FK equivalence test passed on a local server; new
`TableXmlUtils.TestCase` has not run yet. New `ModuleArchiveTestCase`
re-extraction test, which covers the extraction change in
LabKey/server#1562, passed in a standalone JUnit
run. Fresh-database bootstraps and routine restarts ran locally without
errors.

## Tasks
- [x] Claude Code Review
- [x] Manual Testing @labkey-adam 
- [x] Test Automation
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.

2 participants