Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/boot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,10 @@ jobs:

# The runtime budgets (ROADMAP.md, "Fast, robust, light"; gradle/perf-budgets.txt) on Paper,
# with xSample's R8 jar: scripts/budgets/check.sh boots it 4 times for startup, then measures
# heap, metaspace and an idle profile with async-profiler. Over a budget fails the job,
# except startup, which is only reported (a warning in the job summary) until the plugins'
# packaging brings it under 150 ms: 271 ms on an M1 Pro today (DECISIONS.md, "Budgets").
# heap, metaspace and an idle profile with async-profiler. Over any budget fails the job,
# startup's included: 60 ms on an M1 Pro on Paper 1.21.11, 39 ms on 26.3, with Paper handed
# the libraries by the core's loader and the startup classes loaded ahead (DECISIONS.md,
# "Startup under budget").
# Per pull request on the newest Paper without players, a few minutes beside the boots;
# nightly and by hand also the BotMark load, 10 mineflayer bots for a minute, on Paper
# 1.21.11, the newest Minecraft mineflayer speaks and the version M0 measured.
Expand Down Expand Up @@ -389,14 +390,14 @@ jobs:
run: |
newest=$(sed -n 's/^xena\.ciNewestMinecraft=//p' gradle.properties)
scripts/budgets/check.sh --version "$newest" --java "$JAVA_HOME_25_X64" --bots 0 --idle 30 --settle 15 \
--report-only startup-first-ms,startup-ms --out build/budgets/newest \
--out build/budgets/newest \
core/core-testing/sample/bukkit/build/r8/XSample.jar
- name: BotMark load (Paper 1.21.11, 10 bots)
if: github.event_name != 'pull_request'
run: |
scripts/budgets/check.sh --version 1.21.11 --java "$JAVA_HOME_21_X64" --bots 10 \
--commands "xsample,coins,pay {other} 1" \
--report-only startup-first-ms,startup-ms --out build/budgets/botmark \
--out build/budgets/botmark \
core/core-testing/sample/bukkit/build/r8/XSample.jar
- if: always()
uses: actions/upload-artifact@v7
Expand Down
20 changes: 20 additions & 0 deletions DECISIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Why the plugins are built the way they are, oldest first.
| [The update checker and bStats in the rewrite's core: Modrinth's version types as channels, bStats on Bukkit only](#the-update-checker-and-bstats-in-the-rewrites-core-modrinths-version-types-as-channels-bstats-on-bukkit-only-2026-11-24) | 2026-11-24 |
| [Fabric jars relocate their core: one convention, relocation then R8 then Loom](#fabric-jars-relocate-their-core-one-convention-relocation-then-r8-then-loom-2026-11-24) | 2026-11-24 |
| [A real client in the boot tests: one mineflayer bot on Spigot 1.8.8 and Paper 1.21.11](#a-real-client-in-the-boot-tests-one-mineflayer-bot-on-spigot-188-and-paper-12111-2026-11-24) | 2026-11-24 |
| [Startup under budget: Paper gets the libraries from our loader, and the startup classes load ahead](#startup-under-budget-paper-gets-the-libraries-from-our-loader-and-the-startup-classes-load-ahead-2026-11-24) | 2026-11-24 |

## One minimum version: Paper 1.21.11, Java 21 (2026-10-21)

Expand Down Expand Up @@ -713,3 +714,22 @@ Until now no client had joined a boot test, so messages to players, joins and qu
- **Where it runs:** a new per-PR cell, Paper 1.21.11 (the newest Minecraft mineflayer 4.39 speaks; CI's newest Paper is 26.3), and the Spigot 1.8.8 cell, both with `client: true`, which adds Node.js and the bots' cache and the client checks to the cell's boot. Locally the client added about 15 s to a boot (22 s for the whole Spigot 1.8.8 boot, about 30 s for Paper with its paused boot), well under the two minutes a per-PR check may cost, so it isn't nightly-only.
- **Passed locally:** Paper 1.21.11 (Java 21) and Spigot 1.8.8 (Java 8), every check on both.
- **Not yet:** a client on Fabric (mineflayer could join a Fabric server, which needs nothing on the client), the client command tree after a reload (`updateCommands`, which DECISIONS' commands entry still wants confirmed), and Folia, where mineflayer's 26.x support is what's missing.

## Startup under budget: Paper gets the libraries from our loader, and the startup classes load ahead (2026-11-24)

The first plugin's startup was 271 ms against its 150 ms budget (282 on CI), the `budgets` job's one warning (#162). Both fixes the budgets entry above listed are in, and startup fails the job again when over.

| xSample on an M1 Pro, `scripts/budgets/check.sh`, median of 3 boots | Server's part | onLoad | onEnable | Total |
|---|--:|--:|--:|--:|
| Paper 1.21.11 (Java 21), before | 96 | 20.1 | 138.3 | **252.6 ms** |
| Paper 1.21.11, with `paper-plugin.yml` and its loader | 10 | 15.3 | 112.5 | 137.4 ms |
| Paper 1.21.11, and the startup classes loaded ahead | 10 | 15.3 | 34.5 | **59.5 ms** |
| Paper 26.3 (Java 25), before | 78 | 17.7 | 97.5 | **193.9 ms** |
| Paper 26.3, after both | 4 | 4.3 | 30.2 | **39.0 ms** |

- **On Paper, the jar is also a Paper plugin, whose loader hands Paper the libraries.** The jar carries a `paper-plugin.yml` beside its `plugin.yml`; Paper and Folia from 1.19.3 read it, and Spigot and older Paper never look at it. Its `loader` is the core's `PaperLibraryLoader` (core-loader's `paper` source set, Java 17 class files against Paper's API, never shipped with it), which takes each library in `META-INF/xena/libraries.txt` from the family's cache (`plugins/Xena/libraries/`, downloaded and checked against its pin as the shim does below 1.16.5) and gives it to Paper as a `JarLibrary`. That skips Maven's resolver, which Paper ran over `libraries:` at every boot (about 50 ms of CPU, mostly the resolver's own cold code, the same for one library or five), and Paper's legacy-plugin rewriting of every class (Commodore, and the reflection remapper for `libraries:`), which was a third of onEnable. Today's plugins were Paper plugins already, so this is their model, and the API rules hold: a `plugin.yml` plugin with `depend`, or a Paper plugin with `join-classpath`, sees a Paper plugin's API classes (checked in M1, `sandbox/paper-consumer`). Not chosen: the shim injecting the libraries itself on Paper, which needs the JDK's trusted lookup through `sun.misc.Unsafe` and prints the JDK's warning from Java 24, the Java Paper 26 runs on.
- **The classes a plugin needs as it starts are listed at build time and loaded ahead.** `scripts/budgets/check.sh --record-startup` logs a real boot's class loading (`-Xlog:class+load`) and writes the classes loaded before `Done` from the plugin's jar and its libraries (`startup_classes.py`), the jar's in their names before R8 (from its mapping). The project keeps that as `startup-classes.txt`; `shrinkJar` (R8Shrink) maps it to the shrunk jar's names and puts it in the jar as `META-INF/xena/startup-classes.txt`, leaving out classes R8 removed. The shim's preload thread, which loaded a hand list of the stdlib's biggest classes, now loads that list, without initializing anything, between onLoad and onEnable while the server prepares its worlds. xSample's list is 595 classes (299 of its own, the rest the stdlib's and the YAML parser's). A stale list only costs speed: a class it misses loads when first used, one it names that's gone is skipped. Record it again after a large change.
- **What "loads no classes" means now.** The list is recorded with the default config, so a module that's off by default is never in it. A module that's on by default and turned off by the owner still has its classes defined (not initialized: no static state, listeners or tasks), about what the recorded boot needed; ROADMAP.md's rule is about the runtime cost, which is still nothing.
- **What the number counts.** On Paper with `paper-plugin.yml` there's no `libraries:` line to time, so the loader logs its own time (`-Dxena.startupTimes=true`, through the shim's `Startup times` line: `loader 9.5 ms`), most of it hashing the cached jars against their pins. Paper making the plugin's class loader and loading its main class isn't in it: about 8 ms of CPU in a profile, which no log line bounds. Even counted, startup is under the 100 ms a plugin after the first gets.
- **The Boot workflow fails on startup again** (`--report-only` is gone from the `budgets` job). Booted after these changes: Paper 26.3 with the family test (xSample as a Paper plugin, xTwin with `plugin.yml`), Folia 26.3, and Spigot 1.8.8 on Java 8 with the family test, where the shim downloads the libraries and preloads the same list.
- **For each plugin:** a `paper-plugin.yml` naming `co.xenastudios.<plugin>.core.loader.paper.PaperLibraryLoader` (the relocated name; R8 keeps it, from the file), `api-version: '1.19'`, `folia-supported`, and the `dependencies` Paper plugins declare; and a recorded `startup-classes.txt` beside its build file.
7 changes: 7 additions & 0 deletions build-logic/src/main/kotlin/XenaR8Extension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ abstract class XenaR8Extension {

/** The project's own keep rules, after the shared ones: the `.pro` files in its `r8` folder unless set. */
abstract val rules: ConfigurableFileCollection

/**
* The classes the plugin loads as it starts, in their own names, for the shim to load ahead
* (R8Shrink): the project's `startup-classes.txt` if it has one. Record it with
* `scripts/budgets/check.sh --record-startup`.
*/
abstract val startupClasses: ConfigurableFileCollection
}
69 changes: 62 additions & 7 deletions build-logic/src/main/kotlin/co/xenastudios/gradle/R8Shrink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.gradle.api.tasks.CompileClasspath
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
Expand All @@ -41,6 +42,12 @@ import org.gradle.process.ExecOperations
* R8 carries the jar's other files over; Maven's pom files and Kotlin's `.kotlin_builtins`
* (read only by kotlin-reflect) are then dropped. The mapping file stays with the build, for
* stack traces (`retrace`).
*
* [startupClasses], when given, is the list of classes the plugin loads as it starts, in their
* own names (recorded on a real server by `scripts/budgets/check.sh --record-startup`): it goes
* into the jar as [STARTUP_CLASSES] in the names R8 gave them, for the shim to load on a thread
* of its own before the server enables the plugin. A class R8 removed, or that the jar no longer
* has, is left out; the list is a hint, so a missing class only loads when it's first used.
*/
@CacheableTask
abstract class R8Shrink @Inject constructor(private val exec: ExecOperations) : DefaultTask() {
Expand Down Expand Up @@ -76,6 +83,12 @@ abstract class R8Shrink @Inject constructor(private val exec: ExecOperations) :
@get:OutputFile
abstract val mapping: RegularFileProperty

/** The classes the plugin loads as it starts, one a line, in their own names: see the class's comment. */
@get:InputFiles
@get:Optional
@get:PathSensitive(PathSensitivity.NONE)
abstract val startupClasses: ConfigurableFileCollection

/** The rules this task wrote from the jar, kept to read when a rule is missing. */
@get:OutputFile
abstract val generatedRules: RegularFileProperty
Expand Down Expand Up @@ -111,7 +124,7 @@ abstract class R8Shrink @Inject constructor(private val exec: ExecOperations) :
}
val out = outputJar.get().asFile
out.parentFile.mkdirs()
copyWithout(classes, out)
copyWithout(classes, out, startupList(classes))
logger.lifecycle("%s: %.1f KiB -> %.1f KiB".format(out.name, input.length() / 1024.0, out.length() / 1024.0))
}

Expand Down Expand Up @@ -150,21 +163,63 @@ abstract class R8Shrink @Inject constructor(private val exec: ExecOperations) :
}
}

private fun copyWithout(from: File, to: File) {
/**
* [startupClasses] in the shrunk jar's names, or `null` when there's no list. Classes of the
* jar's own (`co.xenastudios.`) must be in the shrunk jar; the rest are the libraries', the
* stdlib's, which R8 never sees, so they keep their names.
*/
private fun startupList(shrunk: File): String? {
val listed = startupClasses.files.filter { it.isFile }
if (listed.isEmpty()) return null
val renamed = HashMap<String, String>()
mapping.get().asFile.forEachLine { line ->
if (!line.startsWith(" ") && !line.startsWith("#") && line.endsWith(":")) {
val (from, to) = line.removeSuffix(":").split(" -> ").takeIf { it.size == 2 } ?: return@forEachLine
renamed[from] = to
}
}
val present = ZipFile(shrunk).use { zip ->
zip.entries().asSequence().filter { it.name.endsWith(".class") }
.map { it.name.removeSuffix(".class").replace('/', '.') }.toHashSet()
}
val names = listed.flatMap { it.readLines() }.map { it.substringBefore('#').trim() }.filter { it.isNotEmpty() }
.mapNotNull { name ->
val now = renamed[name] ?: name
when {
now in present -> now
name.startsWith("co.xenastudios.") -> null
else -> now
}
}
.distinct()
logger.info("${outputJar.get().asFile.name}: ${names.size} startup classes")
return names.joinToString("\n", postfix = "\n")
}

private fun copyWithout(from: File, to: File, startup: String?) {
ZipFile(from).use { zip ->
ZipOutputStream(to.outputStream().buffered()).use { out ->
for (entry in zip.entries().asSequence().sortedBy { it.name }) {
if (entry.name.startsWith("META-INF/maven/") || entry.name.endsWith(".kotlin_builtins")) continue
val entries = zip.entries().asSequence().map { it.name }.filter { it != STARTUP_CLASSES }.toMutableList()
if (startup != null) entries += STARTUP_CLASSES
for (name in entries.sorted()) {
if (name.startsWith("META-INF/maven/") || name.endsWith(".kotlin_builtins")) continue
// Fixed times, so the same input gives the same jar.
out.putNextEntry(ZipEntry(entry.name).apply { time = FIXED_TIME })
zip.getInputStream(entry).use { it.copyTo(out) }
out.putNextEntry(ZipEntry(name).apply { time = FIXED_TIME })
if (name == STARTUP_CLASSES && startup != null) {
out.write(startup.toByteArray())
} else {
zip.getInputStream(zip.getEntry(name)).use { it.copyTo(out) }
}
out.closeEntry()
}
}
}
}

private companion object {
companion object {
/** Where the startup list goes in the jar, which the shim reads (core-loader's BukkitBootstrap). */
const val STARTUP_CLASSES = "META-INF/xena/startup-classes.txt"

// 1980-02-01, as Gradle's reproducible archives use.
const val FIXED_TIME = 318_211_200_000L
}
Expand Down
2 changes: 2 additions & 0 deletions build-logic/src/main/kotlin/xena.r8.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ val xenaR8 = extensions.create<XenaR8Extension>("xenaR8").apply {
"co.xenastudios." + path.split(':').filter { it.isNotEmpty() }.joinToString(".") { it.replace("-", "").lowercase() } + ".r8",
)
rules.convention(fileTree("r8") { include("*.pro") })
startupClasses.convention(files("startup-classes.txt"))
}

plugins.withId("com.gradleup.shadow") {
Expand All @@ -48,6 +49,7 @@ val shrinkJar = tasks.register<R8Shrink>("shrinkJar") {
libraries.from(xenaR8.libraries)
rules.from(xenaR8.rules)
packageName.set(xenaR8.packageName)
startupClasses.from(xenaR8.startupClasses)
// R8 runs on, and reads java.* from, the JDK running the build.
launcher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(JavaVersion.current().majorVersion))
Expand Down
25 changes: 25 additions & 0 deletions core/core-loader/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,28 @@ dependencies {
// The oldest Bukkit API the family runs on, so the shim uses nothing newer.
compileOnly(libs.spigot.api.floor) { isTransitive = false }
}

// Paper's plugin loader (paper-plugin.yml's `loader`), which hands Paper the plugin's libraries
// from the family's cache instead of plugin.yml's `libraries:` (PaperLibraryLoader). Compiled
// against Paper's API, never shipped with it, to Java 17 class files: Paper plugins exist from
// 1.19.3, which ran on Java 17. Main's classes don't see it, so a server without Paper's API
// never loads it.
val paper = sourceSets.create("paper") {
compileClasspath += sourceSets.main.get().output
}
configurations.named(paper.compileClasspathConfigurationName) {
attributes { attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) }
}
dependencies {
"paperCompileOnly"(libs.paper.api)
}
tasks.named<JavaCompile>("compilePaperJava") {
// Paper's API is Java 21 class files, which --release 17 can't read, so -source/-target.
options.release.unset()
sourceCompatibility = "17"
targetCompatibility = "17"
options.compilerArgs.remove("-Werror")
}
tasks.jar {
from(paper.output)
}
Loading