Skip to content

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

Merged
XxFran10xX merged 3 commits into
mainfrom
perf/getholder-no-snapshot
Oct 31, 2026
Merged

XxFran10xX merged 3 commits 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 CompanionPets: StaffMenus.onClick 1.7 s and PetListener.onClick 1.6 s.

Change

  • 10 calls → getHolder(false); the reload loop reads the holder once.
  • Tests: test-only HolderLookupPatch via a JUnit LauncherSessionListener (adds test-scope junit-platform-launcher).

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

  • Same local failures as a clean main run on Windows, class for class; 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

The pet and staff menu listeners run on every inventory click, drag and
close. Each plain getHolder() call copied the whole block state when the
inventory belonged to a chest or barrel. On Main StaffMenus.onClick and
PetListener.onClick cost 3.3 s over 20 hours.

The checks now use getHolder(false), which hands back the same holder
without the copy, and the reload check reads the holder once instead of
twice. Pet and staff menus have their own holders, so the result is the
same object as before. No call site changes a block state, so none were
left as they were.

MockBukkit throws on getHolder(false), so a JUnit session listener
patches its inventories to return their plain holder.

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 →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

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: a8fb6cd9-d4ab-4a86-8b2d-93659f475312

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: aa373a9b-2164-4b69-99d0-6b8f35ecec8f
Commits

Reviewing files that changed from the base of the PR and between 1f4a62b and dac6b4a.

Files selected for processing: 8
  • pom.xml
  • src/main/java/net/tfminecraft/companionpets/PetsPlugin.java
  • src/main/java/net/tfminecraft/companionpets/gui/PetMenus.java
  • src/main/java/net/tfminecraft/companionpets/listen/PetListener.java
  • src/main/java/net/tfminecraft/companionpets/ownership/CharacterLifecycle.java
  • src/main/java/net/tfminecraft/companionpets/staff/StaffMenus.java
  • src/test/java/net/tfminecraft/companionpets/testutil/HolderLookupPatch.java
  • src/test/resources/META-INF/services/org.junit.platform.launcher.LauncherSessionListener

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 and pet/staff menu handling now checks existing menu ownership during interactions, closures, settings reloads, and character transitions. This avoids creating inventory holders during checks while preserving existing menu behaviour.

Runtime inventory checks now retrieve holders with getHolder(false). Test setup registers a JUnit launcher-session listener that patches InventoryMock.getHolder(boolean).

Changes: Inventory holder lookup

Layer / File(s) Summary
Runtime inventory holder checks
src/main/java/net/tfminecraft/companionpets/PetsPlugin.java, src/main/java/net/tfminecraft/companionpets/gui/PetMenus.java, src/main/java/net/tfminecraft/companionpets/listen/PetListener.java, src/main/java/net/tfminecraft/companionpets/ownership/CharacterLifecycle.java, src/main/java/net/tfminecraft/companionpets/staff/StaffMenus.java
Menu and inventory checks now call getHolder(false). Existing type checks and subsequent handling remain unchanged.
Test holder lookup compatibility
pom.xml, src/test/java/net/tfminecraft/companionpets/testutil/HolderLookupPatch.java, src/test/resources/META-INF/services/org.junit.platform.launcher.LauncherSessionListener
The test dependencies include junit-platform-launcher. Its session listener installs a Byte Buddy patch that replaces InventoryMock.getHolder(boolean) with a call to inventory.getHolder().

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: nowkoo, ryanbarlow97

Merge Risk: Minimal · previous review dac6b

The holder lookup change has no identified merge-blocking issue.

- [ ] 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:S 10-29 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.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 31, 2026
Byte Buddy reports a failed retransformation only to its listeners and
returns normally, so the patch counted as installed even when
InventoryMock kept its throwing getHolder(boolean). It now marks itself
installed only after InventoryMock was transformed, and stops the test
session with a clear error otherwise (CodeRabbit).

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

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 31, 2026

Copy link
Copy Markdown

Rate Limit Exceeded

@XxFran10xX have exceeded the limit for the number of chat messages per hour. Please wait 7 minutes and 38 seconds before sending another message.

onTransformation fires before the JVM applies the new bytes, so a
rejection in retransformClasses reaches only onError. The patch now fails
the test session in that case too (Opus review).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XxFran10xX
XxFran10xX merged commit cfd70f8 into main Oct 31, 2026
3 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:S 10-29 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant