Skip to content

perf: read inventory holders without copying the block - #36

Merged
XxFran10xX merged 1 commit into
mainfrom
perf/getholder-no-snapshot
Oct 31, 2026
Merged

XxFran10xX merged 1 commit into
mainfrom
perf/getholder-no-snapshot

Conversation

@XxFran10xX

@XxFran10xX XxFran10xX commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Why

Main profiles, 20 hourly spark dumps 10-30 10:00 → 10-31 05:00 (peak 37 players). Inventory#getHolder() without an argument builds a full BlockState copy when the inventory belongs to a block (chest, barrel, double chest), and every plugin's click/open listener calls it again. Over the 20 h that cost ~200 s of main-thread time, mostly as short stalls on clicks in heavy containers; one click at 04:01 took 2.0 s. In MusicalInstruments: StudioMenu.open 20.8 s and StudioMenu.click 1.6 s.

Change

  • 4 getHolder() calls in StudioMenu and the jukebox hopper guard → getHolder(false).

For plugin menus the holder is the plugin's own object, so the result is identical. For real block inventories the code only type-checks or reads the holder, so the live state gives the same answer. Nothing players see changes.

Testing

  • 419/419 tests. Locally, the folder-fsync tests fail on Windows the same way as on main; Linux CI is the check.
  • Dev (TFMCDev01, 10-31 from 11:47 UTC): this PR's jar ran together with the other 12 jars from this round (VF, SF, MusicalInstruments, Magic on the Blood Magic branch, TLibs, GunsAndGadgets, Thievery, BirdMessenger, Surgery, CompanionPets, ActivityTF, MarketBlock), through two restarts. No error from any of them in the log. Bot TestChar1:
    • A chest, a double chest and a barrel, each full of shulker boxes of written books: open, pick up and put back, shift-click both ways. Every plugin's click/open listener ran; the stacks stayed intact and nothing was logged.
    • /faction list (row click works), /referral and /activity menus opened and worked.

🤖 Generated with Claude Code

Opening and clicking the studio menu was slow on Main because every
getHolder() call on a container inventory copies the whole block state,
so a click with a large chest open could stall the server. The menu and
the jukebox hopper check now use getHolder(false), which returns the same
holder without the copy. The code only checks the holder's type, so
behaviour does not change. No call site needed the copying form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b26a20df-be7a-4994-88c7-072ea54f7de2
Commits

Reviewing files that changed from the base of the PR and between 0bcee4e and 267f610.

Files selected for processing: 4
  • src/main/java/net/tfminecraft/musicalinstruments/studio/StudioListener.java
  • src/main/java/net/tfminecraft/musicalinstruments/studio/StudioMenu.java
  • src/test/java/net/tfminecraft/musicalinstruments/studio/StudioListenerTest.java
  • src/test/java/net/tfminecraft/musicalinstruments/studio/StudioMenuTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Inventory handling now checks for an existing holder without requesting that one be created. This applies to hopper transfers involving jukeboxes and interactions with the studio inventory.
    • Existing behavior is unchanged: custom-disc transfers into jukeboxes are still cancelled, while transfers into inventories without a holder are not. These checks no longer create a holder as a side effect.

Studio menu and hopper checks now use getHolder(false). The tests update their inventory mocks and holder stubs to match.

Changes: Studio inventory holder lookups

Layer / File(s) Summary
Use non-creating holder lookups
src/main/java/net/tfminecraft/musicalinstruments/studio/StudioMenu.java, src/main/java/net/tfminecraft/musicalinstruments/studio/StudioListener.java, src/test/java/net/tfminecraft/musicalinstruments/studio/StudioMenuTest.java, src/test/java/net/tfminecraft/musicalinstruments/studio/StudioListenerTest.java
Menu and hopper holder checks now call getHolder(false). The tests stub that method for the menu inventory, jukebox, and null-holder cases.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Refactor

Suggested reviewers: nowkoo

Merge Risk: Minimal · up to 267f6

The change avoids block-state snapshots without an established behavior regression or merge-blocking risk.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added the size:XS 0-9 effective changed lines (tests excluded in mixed PRs). label Oct 31, 2026
@XxFran10xX
XxFran10xX marked this pull request as ready for review October 31, 2026 12:42
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@XxFran10xX
XxFran10xX merged commit 5f1d764 into main Oct 31, 2026
4 checks passed
@XxFran10xX
XxFran10xX deleted the perf/getholder-no-snapshot branch October 31, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant