Skip to content

perf(build): smaller jars, with R8's marker stripped, a short package and fewer keep rules - #169

Merged
zacharyk812 merged 2 commits into
mainfrom
perf/jar-size
Nov 25, 2026
Merged

zacharyk812 merged 2 commits into
mainfrom
perf/jar-size

Conversation

@zacharyk812

@zacharyk812 zacharyk812 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #123. Based on main now that #166 (startup) has merged.

Every shrunk jar loses a fifth, through build-logic, so every plugin gets it. DECISIONS.md: "Smaller jars".

What changed

  • R8's marker emptied (R8Shrink.withoutMarker): R8 writes a 186-byte ~~R8{...} string as constant Dependency Dashboard #1 of every class, which nothing reads at runtime. The string is emptied in place, so no index changes. This was 11% of xUtilities' jar.
  • Renamed classes go to a package named for the plugin (xsample, xutilities), not co.xenastudios.<id>.r8. Every class name and descriptor carries that package, so this saves 6.5%. The name is still unique per server. The default comes from the project path's first name; on Fabric it's the mod id. analyze.py now counts a plugin's R8 package as its own in samples and heap.
  • The relocated core's api packages are no longer kept whole. common.pro keeps the plugin's own API (api packages outside core). shrinkJar generates keep rules for exactly the core types that API names, followed transitively (for xUtilities: PlayerRef, Location, WorldRef, the event types).
  • No enum keep rule. It was there for Cloud and Guice, and the rewrite uses neither. The rule is in a comment for any plugin that needs it.
  • Only runtime-visible annotations are kept. Line numbers stay, and so does the single source file name.
  • The jar is written at deflate level 9, without data descriptors. Sizes and CRC are computed up front; that saves 16 B an entry. Kotlin's .kotlin_module files are dropped.
  • Budgets lowered to the new sizes plus about 10%.

Sizes (KiB, shrunk jar; Fabric before Loom's remap)

Jar Before After
xSample, Bukkit 521.0 417.5 -20%
xTwin, Bukkit 400.8 310.9 -22%
xSample, Fabric 1.20.1 / 1.21.11 / 26.3 431.3 / 432.3 / 445.4 332.1 / 333.0 / 346.1 -23%
xTwin, Fabric 1.20.1 / 1.21.11 / 26.3 358.1 / 360.3 / 373.4 268.6 / 269.7 / 282.8 -25%
Loader sandbox 28 27.2
xUtilities 3.0, Bukkit (#167, local scratch merge) 573.6 477.3 -17%
xUtilities 3.0, Fabric 1.20.1 / 1.21.11 / 26.3 (#167) 527.7 / 528.6 / 541.8 437.9 / 439.0 / 452.2 -17%

Per step, measured on xUtilities' Bukkit jar (KB, deflate 9):

Step Size
before 579
narrower API keep, no enum rule, runtime annotations only 563
R8's marker emptied 499
package xutilities 467

xUtilities is still about three times its 2.x jar (163 KiB). What's left is the core's own code, reachable through what the plugin uses.

Tried, not taken

  • -assumenosideeffects on Kotlin's Intrinsics null checks: under 0.3%, and the checks are useful.
  • Bundling the lang drafts into one entry: saves 6 KB, but needs a LangFiles change.
  • Dropping the shaded modules from R8's library jars: no size change.
  • -allowaccessmodification: R8 is already in full mode, so no change.
  • Making the database layer lazy: R8 already strips the import and migrate paths. The Table, ColumnType and SqlValue that remain describe the family player cache's file, which xUtilities uses.

Checked

  • ./gradlew build: ABI, jar budgets, the new R8ShrinkTest, and JarBootTest on both jars.
  • ./gradlew -p core/platform-fabric build collect.
  • Family test (xSample + xTwin) passes on Paper 26.3, Spigot 1.8.8 (Zulu 8) and Fabric 26.3.
  • scripts/budgets/check.sh: xSample startup is unchanged on the same machine (Paper 26.3: 41.0 ms vs 40.7 ms on the old jar; 1.21.11: 71.1 vs 71.0 ms). The startup list still maps 594 of 595 classes; R8 now merges one away. xTwin's startup is over 100 ms both before and after (136.5 / 123.5 ms). That isn't new, and CI budgets xSample only.

Not checked: Fabric 1.20.1 and 1.21.11 boots (both built and within budget), Folia, and real boots of xUtilities. #167 needs a follow-up: its packageName = "co.xenastudios.xutilities.r8" lines should go, so the default applies, and its jar-budget lines should drop to about 525 / 480–500 KiB.

The jar rule

After these cuts xUtilities 3.0 is still about 477 KiB against 2.x's 163 KiB. The owner set the rule to 500 KiB per jar on every platform; ROADMAP.md and a DECISIONS.md bullet say so, and each jar's line in gradle/jar-budgets.txt still sits about 10% over its size.

@github-actions github-actions Bot added documentation Improvements or additions to documentation core The shared core and build labels Nov 25, 2026
… and fewer keep rules

Every shrunk jar loses a fifth: R8's per-class marker string is emptied,
renamed classes go to a package named for the plugin (xsample, not
co.xenastudios.xsample.r8), the relocated core's api packages are kept only
as far as the plugin's own API exposes them, the enum keep rule and the
compile-time annotations go, and the jar is written at deflate's strongest
level without data descriptors. xSample's Bukkit jar 521 -> 418 KiB, xTwin's
401 -> 311 KiB, the Fabric jars 23-25% smaller, xUtilities 3.0 574 -> 477 KiB.
Budgets lowered to the new sizes plus about 10%. The budget check counts a
plugin's R8 package as its own.

Part of #123.
@zacharyk812
zacharyk812 marked this pull request as ready for review November 25, 2026 03:35
@zacharyk812
zacharyk812 merged commit 26b3808 into main Nov 25, 2026
31 checks passed
@zacharyk812
zacharyk812 deleted the perf/jar-size branch November 25, 2026 03:45
@zacharyk812 zacharyk812 mentioned this pull request Nov 25, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core The shared core and build documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant