Skip to content

Anvil trimming optimization for very large servers - #14209

Open
mattiapearl wants to merge 1 commit into
PaperMC:mainfrom
mattiapearl:research/trim-region-file-tail
Open

Anvil trimming optimization for very large servers#14209
mattiapearl wants to merge 1 commit into
PaperMC:mainfrom
mattiapearl:research/trim-region-file-tail

Conversation

@mattiapearl

Copy link
Copy Markdown

The idea is that long-lived region files can retain physically unused trailing sectors with no purpose. We can return this trailing space to the filesystem. It's not a form of general compression. NICHE optimization for extremely large servers.

Benchmarks

  • Executor: Pi AI agent
  • Direction and code review: contributor

Final Paper implementation

Actual RegionFile, 256 deterministic 32 KiB records, repeated grow/shrink operations across three paired runs:

Metric Stock Candidate
Full file 9,441,301 B 9,441,301 B
Trailing half cleared 9,441,301 B 4,726,784 B
Everything cleared 9,441,301 B 8,192 B
Interior deletion 9,441,301 B 9,441,301 B
Shrinking-flush median 1.4402 ms 1.3872 ms
Shrinking-flush p95 24.4105 ms 15.0366 ms
Clear-all flush median 0.4557 ms 1.2518 ms

Earlier five-pair Folia campaign

The same physical-space behavior was measured through actual RegionFile operations:

  • Constructed trailing-half deletion reclaimed 49.94%.
  • Clearing all records reclaimed 99.91%.
  • Interior holes remained.
  • Retained payloads survived flush, close, and reopen.
  • The earlier implementation's shrinking-flush median was 9.10 ms stock versus 15.97 ms patched; the final implementation added a dirty-tail flag to avoid unnecessary truncation checks.

Fresh-world scan

  • 1,128 .mca files
  • 151,533 records
  • 683,713,425 total bytes
  • 0 files with reclaimable tails
  • 0 reclaimable bytes

Final Folia integration smoke

  • Full file: 9,441,301 B
  • Trailing half cleared: 4,726,784 B
  • Everything cleared: 8,192 B
  • Interior-only deletion: 9,441,301 B
  • Retained payload verification passed.

AI assistance disclosure

  • AI materially assisted—not merely autocomplete.
  • Primary model: gpt-5.6-sol, maximum reasoning.
  • Seven gpt-5.6-terra:medium research agents.
  • Two gpt-5.6-luna:low read-only scouts.
  • Assistance covered research, code inspection, implementation, tests, benchmark harnesses, analysis, and issue/PR searches.
  • No independent AI reviewer was used.
  • The passive review ledger only recorded prompts/responses; it did not perform review.
  • I reviewed all the code, understand it, and accept responsibility for the contribution.

@mattiapearl
mattiapearl requested a review from a team as a code owner August 23, 2026 11:44
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Aug 23, 2026
Truncate unallocated sectors after region data has been forced to disk and when region files close. Keep flush and close coordinated with writes, and cover clearing, replacement, reopening, and retained live data.
@mattiapearl
mattiapearl force-pushed the research/trim-region-file-tail branch from 66c8b5d to 729ad0a Compare August 23, 2026 16:21
@electronicboy

Copy link
Copy Markdown
Member

Not fond of this being a core file patch, and generally concerned that this is just something that won't be able to be tested enough for us to guarantee its safety across updates, etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

2 participants