Skip to content

perf: read the artifact key through the stack's data view - #72

Merged
XxFran10xX merged 1 commit into
mainfrom
perf/item-scan-cost
Oct 29, 2026
Merged

XxFran10xX merged 1 commit into
mainfrom
perf/item-scan-cost

Conversation

@XxFran10xX

Copy link
Copy Markdown
Contributor

Companion PR: TF-Minecraft/Cooking#98 (same scan path: Cooking's food and fish checks, plus kept ItemsAdder templates).

Why

TLibs ItemScanService scans one player's inventory (plus any open container) every 2 ticks. It calls every registered handler's matches() on every non-air slot. Magic's ArtifactAttuneScanHandler.matches → ArtifactIds.hasKey called hasItemMeta() and then getItemMeta() to test for the artifact_id key. Inventory.getItem returns a mirror, so each getItemMeta() builds a full CraftMetaItem. That copies every component and the whole custom-data tag, which is large on MMOItems and ItemsAdder items. This happened once per slot, 10 scans a second, only to read one key.

Changes

  • ArtifactIds.hasKey now reads the key through ItemStack#getPersistentDataContainer(), the read-only PersistentDataContainerView in Paper 1.21.10 API (confirmed in the paper-api-1.21.10-R0.1-SNAPSHOT jar the pom compiles against). It checks the same key with the same STRING type.
  • The listener, frame-care and meditation callers of hasKey get the same saving.
  • ArtifactCareStore.apply in update() is untouched. It only runs for artifacts.

Why behaviour is identical

The view and getItemMeta().getPersistentDataContainer() read the same PublicBukkitValues compound in custom_data, with the same type check. The dropped hasItemMeta() guard could only ever reject items whose PDC is empty, and those already answer false. Null and air still answer false before any read. The scan runs on the server thread, and nothing changes about when it runs or what update() does.

Testing

  • New ArtifactIdsKeyViewTest compares hasKey (and ArtifactAttuneScanHandler.matches) against a copy of the origin/main implementation. It covers null, air, items with and without meta, written artifacts, a blank id, the id stored as a number, another artifact key only, and the id under another namespace.
  • ChargeEdgeCoverageTest stubs the data view on its mocked no-meta stack, because Mockito returns null where Paper always returns a view.
  • mvn -B -o clean verify on Windows: the only failures are the same 147 Windows-only gear.ownership file tests that fail on origin/main, and the jacoco gaps match origin/main exactly. Linux CI is authoritative.

Dev testing on TFMCDev01 follows before this leaves draft.

🤖 Generated with Claude Code

The TLibs item scan calls ArtifactAttuneScanHandler.matches() on every
non-air slot ten times a second. ArtifactIds.hasKey copied the whole
item meta to test one key; it now reads the key through the read-only
ItemStack#getPersistentDataContainer view, with the same answers for
items with and without meta.

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

coderabbitai Bot commented Oct 29, 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: f6019549-b238-47f5-8bb4-963dafdaac17
Commits

Reviewing files that changed from the base of the PR and between 8903481 and 8afa321.

Files selected for processing: 3
  • src/main/java/net/tfminecraft/magic/artifact/ArtifactIds.java
  • src/test/java/net/tfminecraft/magic/ChargeEdgeCoverageTest.java
  • src/test/java/net/tfminecraft/magic/artifact/ArtifactIdsKeyViewTest.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
    • Artifact identification now reads the ID directly from an item’s stored data, so valid artifact IDs can be recognised even when the item has no metadata. Existing checks continue to reject missing items, air, and IDs stored in an invalid format. This improves consistent artifact and attunement recognition across items with different metadata states.

ArtifactIds.hasKey now reads the artifact ID from the stack’s persistent data container after the existing null and air checks. Tests cover matching behaviour across metadata and identifier cases.

Changes: Artifact key lookup

Layer / File(s) Summary
Direct persistent-data key check
src/main/java/net/tfminecraft/magic/artifact/ArtifactIds.java, src/test/java/net/tfminecraft/magic/artifact/ArtifactIdsKeyViewTest.java, src/test/java/net/tfminecraft/magic/ChargeEdgeCoverageTest.java
ArtifactIds.hasKey reads the stack’s persistent data container directly. Tests compare artifact and attunement checks with a full-meta reference and provide an empty persistent-data container for the no-metadata case.

Priority: Low

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

Change: Refactor

Suggested labels: size:S

Suggested reviewers: ryanbarlow97

Merge Risk: Minimal · up to 8afa3

Artifact key lookups should retain their prior behavior. No merge-blocking issue was identified; run the standard CI checks before merging.

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

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the size:XS 0-9 effective changed lines (tests excluded in mixed PRs). label Oct 29, 2026
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

Dev test (TFMCDev01, 10-29 13:26 UTC; ~/perf-1029-test/scan.js on tf): PASS

Built as feat/bloodmagic-progression + this PR (Dev runs the bloodmagic build), so Dev keeps its bloodmagic features. An artifact given with magic artifact give keeps all its data while the scan runs (8 s, and after a Cooking reload), and the log shows no Magic errors across three restarts. The scan-path change is a pure read; behaviour parity is covered by ArtifactIdsKeyViewTest.

@XxFran10xX
XxFran10xX marked this pull request as ready for review October 29, 2026 13:38
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 29, 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 53403a6 into main Oct 29, 2026
4 checks passed
@XxFran10xX
XxFran10xX deleted the perf/item-scan-cost branch October 29, 2026 13:57
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