Skip to content

perf: cheaper sketch kit pass, tracker hand check and Hand Pick state lookup - #42

Merged
XxFran10xX merged 1 commit into
mainfrom
perf/hud-kit-tracker-costs
Nov 11, 2026
Merged

XxFran10xX merged 1 commit into
mainfrom
perf/hud-kit-tracker-costs

Conversation

@XxFran10xX

Copy link
Copy Markdown
Contributor

Summary

Performance-only fixes for three hot spots in a one-hour Main spark profile at 60 players (72,000 ms/h = 1 ms per tick). Nothing a player sees or does changes.

Hot spot Measured What was slow
SketchService.stampKitsLater 8.0 s/h unstackCarried copied the metadata of every carried item (CraftItemStack.getItemMeta, 5.7 s); stampAll asked the pack plugins about every item (ItemMatcher, 1.6 s)
TrackerService.pulse 3.6 s/h holdingTracker read both hands' item data through MMOItems for every player on every pulse (3.0 s)
HandPickService.tick → syncAndShowHud 8.6 s/h action-bar send 3.6 s, heldTool 2.1 s (DigTools.match 0.8 s, state() lookup 0.5 s), aimedNearSite 0.85 s

What changed

Sketch kit pass

  • markUnstackable checks the item type first. Only a filled map has MapMeta, so every other item is skipped without copying its metadata. Filled maps, sketch or not, are handled exactly as before.
  • stampInstructions only matches a stack against sketch.paper / sketch.pencil when that entry is a vanilla item. A pack sheet or pencil never gets Archaeo lore (that was already the rule, checked last), so the pack plugin is no longer asked about every item in the bag first.
  • Several stampKitsLater calls for one player in the same tick (a pile of drops picked up, a click and a close, fast hotbar scrolling) now scan the bag once. Each call still queues its task; only the newest one for that player does the work, and it runs at the same point as before.

Tracker

  • holdingTracker remembers each player's two hand stacks and the answer. It matches again only when a stack changes (ItemStack equality against stored copies, so wear, renames and data changes count), after 20 ticks, on /archaeo reload, or when the pack-plugin matcher is rebound. This is the same approach HandPickService.heldTool already uses.
  • ItemMatcher.matchesMmoItems reads the MMOItems id only when the type already fits. Type and id are two separate reads of the item data; the answer is the same. This also helps the Hand Pick whitelist match and every other MMOItems check.

Hand Pick HUD

  • The per-player shortcut state is looked up once per player per tick and passed to heldTool, keepVanillaMineUnlocked and setVanillaMineLocked, instead of once in each.
  • The whitelist match gets cheaper through the matchesMmoItems change above.

Not changed, and why

  • The action-bar send (3.6 s/h, the largest single cost). It is still sent every tick with the same call. MMOCore redraws its own bar every few ticks and Archaeo does not reserve the bar through MythicLib's ActionBarHandler, so sending less often would let the MMOCore bar show through. The cost is inside the send itself, so reusing the text or the component object would save nothing. Two options exist but both change behaviour and need a Dev check, so they are left for a separate PR: sending through Paper's sendActionBar (cheaper, but it is a different packet: action_bar instead of overlay system_chat), or reserving the bar through MythicLib and sending only when the text changes.
  • The tool match for players far from any dig. It also strips the old item-level mining lock from a whitelisted tool wherever the player is, so skipping it away from sites would not be neutral.
  • aimedNearSite / hasEstablishedIn. The site status is read live on purpose; remembering the answer per player would not be exact.

Behaviour notes

  • Tracker: if a pack plugin reloads its registry and that changes whether an unchanged held stack is the tracker, the pulse notices within 1 s instead of on the next pulse. Only ItemsAdder ids depend on a registry; MMOItems ids are stored on the item. A hand change is still seen on the very next pulse.
  • Sketch kits: if a second kit pass for a player is requested from inside the scheduler run, before the first has run, the pass happens once on the next tick instead of once on each of the two ticks. The bag ends in the same state.

Tests

  • Full mvn -B clean verify on Windows: 825 tests, 2 skipped, 3 failures. The 3 failures are the SiteEstatesTest cases that also fail on unmodified main on Windows (they look for ownership/journals with a forward slash in a Windows path); I ran that class on a clean copy of origin/main to confirm. With that class left out, the other 797 tests pass and the jar builds. Linux CI is authoritative.
  • New and adjusted tests:
    • TrackerServiceTest: the hands are matched once per pair, again after 20 ticks, at once on any stack change (new item, same type with different data, item removed), and after itemChanged, setSettings and stop.
    • SketchServiceTest: three kit requests in one tick scan the bag once and still stamp the lore; later ticks and other players get their own pass; unstackCarried never copies the metadata of a non-map item and still caps a plain filled map at one per slot.
    • SketchSuppliesTest: pack-configured supplies are never matched during a bag scan; a vanilla sheet next to a pack pencil is still matched.
    • ItemMatcherPackIT (optional pack-api-tests profile, run locally against the ItemsAdder, FastNbt, MMOItems and MythicLib jars: 10 + 7 tests pass): a stack without an MMOItems type is not asked for its id.

Test plan

  • Dev: field sheet + pencil → sketch map, stacked sketch maps split into single maps, a given kit sheet with its lore removed gets it back on the next inventory click
  • Dev: tracker in main hand and in off hand starts pulsing at once; putting it away stops it at once; /archaeo reload while holding it keeps it working
  • Dev: Hand Pick HUD and mining lock unchanged when aiming at fill, opened air and sky, and when swapping items
  • Main spark after release: getItemMeta gone from stampKitsLater, matchesMmoItems gone from TrackerService.pulse

🤖 Generated with Claude Code

…er hand check, look up Hand Pick state once

A one-hour Main spark profile at 60 players put SketchService.stampKitsLater
at 8.0 s, TrackerService.pulse at 3.6 s and the Hand Pick HUD pass at 8.6 s
of main-thread time. These changes keep every result the same.

- Sketch kits: markUnstackable checks the item type before copying
  metadata (only a filled map has MapMeta); stampInstructions matches a
  stack only against a vanilla sheet or pencil, since pack supplies never
  get Archaeo lore; several stampKitsLater calls for one player in one
  tick scan the bag once, in the newest request.
- Tracker: holdingTracker remembers both hand stacks and the answer, and
  matches again when a stack changes (ItemStack equality), after 20
  ticks, on reload, or when the pack-plugin matcher is rebound.
- ItemMatcher: the MMOItems id is read only when the type already fits;
  type and id are separate reads of the item data.
- Hand Pick: the per-player shortcut state is looked up once per player
  per tick and passed to the held-tool match and the mining-lock steps.

The per-tick action-bar send is unchanged: MMOCore redraws its own bar
and Archaeo does not reserve it, so sending less often could let that
bar show through.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added the size:L 100-499 effective changed lines (tests excluded in mixed PRs). label Nov 11, 2026
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Pack-configured sketch supplies now retain their existing lore instead of being treated like vanilla paper or pencils.
    • Ordinary items are no longer inspected as tracker tools or maps, helping prevent incorrect item handling.
    • Filled maps carried in a stack are limited to one per stack.
    • Tracker updates now reflect changes to held items and settings, and deferred sketch-kit processing avoids redundant passes.

The change adds cached hand checks for trackers and passes held state through excavation-tool handling. It checks MMOItems type before reading an ID, gates sketch supply stamping by item kind, coalesces deferred kit-stamping requests per player, and limits map metadata checks to filled maps.

Changes: Item matching and cached hand state

Layer / File(s) Summary
Tracker hand cache
src/main/java/net/tfminecraft/archaeo/tracker/TrackerService.java, src/main/java/net/tfminecraft/archaeo/ArcheologyPlugin.java, src/test/java/net/tfminecraft/archaeo/tracker/TrackerServiceTest.java
TrackerService reuses hand-match results while the cached stacks remain unchanged and the 20-tick interval has not elapsed. Settings changes, tracker item changes, and stopping clear the cache. Tests cover reuse and refresh conditions.
Excavation held-state reuse
src/main/java/net/tfminecraft/archaeo/excavation/HandPickService.java
HandPickService passes HeldState into tool matching, HUD handling, and mining-lock updates instead of looking it up in each method.
MMOItems type check
src/main/java/net/tfminecraft/archaeo/item/ItemMatcher.java, src/test/java/net/tfminecraft/archaeo/item/ItemMatcherPackIT.java
MMOItems matching checks the probed type before reading the item ID. The integration test verifies that an item with a non-matching type does not trigger ID lookup.

Sketch supply and map safeguards

Layer / File(s) Summary
Vanilla supply stamping
src/main/java/net/tfminecraft/archaeo/item/SketchSupplies.java, src/test/java/net/tfminecraft/archaeo/item/SketchSuppliesTest.java
Paper and pencil matching and stamping checks run only when their configured item references are vanilla. Tests verify matcher calls and unchanged lore for pack supplies.
Deferred stamping and map handling
src/main/java/net/tfminecraft/archaeo/sketch/SketchService.java, src/test/java/net/tfminecraft/archaeo/sketch/SketchServiceTest.java
Only the newest deferred kit-stamping request for a player proceeds. Map metadata is checked only for filled maps. Tests cover request coalescing, player independence, and filled-map stack limits.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

  • TF-Minecraft/Archaeo#40: It also changes held-tool matching and matcher invalidation in ArcheologyPlugin.bindItemMatcher.
  • TF-Minecraft/Archaeo#37: It changes the MMOItems matching path and overlaps with HandPickService tool checks.

Suggested reviewers: nowkoo, ryanbarlow97

Merge Risk: Minimal · up to 46d5f

This performance-focused change keeps player-visible behavior the same and has no identified merge-blocking risk. Normal CI on Linux should confirm the build.

- [ ] 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

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: 5b76bbdd-fd99-4656-89b5-5befdfc7f0fc
Commits

Reviewing files that changed from the base of the PR and between c9d9963 and 46d5fa3.

Files selected for processing: 10

  • src/main/java/net/tfminecraft/archaeo/ArcheologyPlugin.java
  • src/main/java/net/tfminecraft/archaeo/excavation/HandPickService.java
  • src/main/java/net/tfminecraft/archaeo/item/ItemMatcher.java
  • src/main/java/net/tfminecraft/archaeo/item/SketchSupplies.java
  • src/main/java/net/tfminecraft/archaeo/sketch/SketchService.java
  • src/main/java/net/tfminecraft/archaeo/tracker/TrackerService.java
  • src/test/java/net/tfminecraft/archaeo/item/ItemMatcherPackIT.java
  • src/test/java/net/tfminecraft/archaeo/item/SketchSuppliesTest.java
  • src/test/java/net/tfminecraft/archaeo/sketch/SketchServiceTest.java
  • src/test/java/net/tfminecraft/archaeo/tracker/TrackerServiceTest.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.

@XxFran10xX
XxFran10xX marked this pull request as ready for review November 11, 2026 23:39
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 11, 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 f888af1 into main Nov 11, 2026
8 checks passed
@XxFran10xX
XxFran10xX deleted the perf/hud-kit-tracker-costs branch November 11, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant