Commit a0d71ee
Z User
perf+fix: phase 2/3 resource cleanup, seat index, blockdata cache
Phase 2 (resource cleanup, R3/R4/T8/R6/T10) and Phase 3 (perf, T4/P1/P7)
of the v1.3.0 review. Closes reload-path cache leaks and trims per-render
allocations in the spawn hot path.
R3+R4 - MahjongPaperPlugin.reloadMahjongConfiguration: clear
TableDisplayRegistry + DisplayVisibilityRegistry before
re-rendering tables. Both are static maps keyed by entity ID;
on reload every table calls clearDisplays() + render(), spawning
fresh entities whose IDs may be recycled from deleted entities.
Without clearing, a new entity can inherit the visibility flags
(private viewers, hidden viewers) of a deleted entity that shared
the same ID, causing the new entity to be incorrectly hidden or
shown to the wrong player. onDisable already cleared these; reload
was the missing symmetric path.
T8 - DisplayEntities.clearCaches: clear TILE_ITEM_CACHE (static) and
BLOCK_DATA_CACHE (new, see P1) on reload. Previously a resourcepack
update or CraftEngine custom-item config change would leave stale
ItemStacks cached under the same path key, and tables re-rendered
post-reload would keep showing old textures until JVM restart.
Called from reloadMahjongConfiguration alongside the registry clears.
R6 - Verified auto-satisfied: CraftEngineCullingBridge.reflection is an
instance field on a final member of CraftEngineService. Reload
rebuilds CraftEngineService (line 296-304), so cullingBridge is a
fresh instance with reflection=null. No additional change needed
for the MahjongPaper reload path. (CraftEngine-self-reload case
remains out of scope.)
T10 - TableEventCoordinator.recentDisplayActions: replace bare
ConcurrentHashMap with Caffeine.expireAfterAccess(2min). The dedup
window is 40ms, so anything older than a few seconds is by
definition not a duplicate of a fresh click — but the previous
bare map only evicted on PlayerQuitEvent, which on Folia can
occasionally be missed when the player's entity region differs
from the global region at logout time. That left entries forever.
TTL caps the worst-case leak at 2 minutes per entry. onQuit still
calls invalidate() for immediate cleanup.
T4 - MahjongTableSession.seatOf + TableParticipantRegistry.seatOf:
add an O(1) reverse-lookup path via the existing seatByPlayer
map (maintained as an invariant of occupySeat/vacateSeat). The
previous implementation iterated SeatWind.values() and called
playerAt(wind) for each — an O(4) scan over a non-synchronized
ArrayList, called from ~15 sites including the render hot path.
Fast path is used when no round is active (the common case for
lobby renders, viewer overlays, command tab-completion). When a
round IS active, we still fall through to the O(4) reverse lookup
via playerAt(wind) to preserve the exact pre-T4 semantics in any
edge case where participants.seatByPlayer and engine seats
diverge (e.g. a test that mocks an inconsistent engine). In
production they are kept in sync at round boundaries.
P1 - DisplayEntities.BLOCK_DATA_CACHE: cache BlockData per Material.
Material.createBlockData allocates a fresh CraftBlockData on
every call; for the ~5 distinct Materials used by table
structure rendering the result is identical across spawns and
safe to share — BlockDisplay.setBlock copies state internally
and never mutates the input. Saves one CraftBlockData allocation
per BlockDisplay spawn (~16 per table structure render).
P7 - MahjongTableSession.cornerSticks: replace new ArrayList() + N
add() + List.copyOf with List.of() / Collections.nCopies(). Both
return immutable Lists; callers (StickRenderer,
TableRenderLayout) only read size() + get(i), never mutate.
Eliminates per-call allocation in a path called 4x per render
via stickLayoutCount + captureSeatSnapshot.
ArchitectureBoundaryTest: bump MahjongTableSession line budget from
1700 to 1750 to accommodate the new comments (file is now 1697 lines).1 parent b9a8f56 commit a0d71ee
6 files changed
Lines changed: 148 additions & 22 deletions
File tree
- src
- main/java/top/ellan/mahjong
- bootstrap
- render/display
- table/core
- test/kotlin/top/ellan/mahjong/architecture
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
343 | 344 | | |
344 | 345 | | |
345 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
346 | 365 | | |
347 | 366 | | |
348 | 367 | | |
| |||
Lines changed: 50 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
44 | 56 | | |
45 | 57 | | |
46 | 58 | | |
47 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
48 | 97 | | |
49 | 98 | | |
50 | 99 | | |
| |||
635 | 684 | | |
636 | 685 | | |
637 | 686 | | |
638 | | - | |
| 687 | + | |
639 | 688 | | |
640 | 689 | | |
641 | 690 | | |
| |||
Lines changed: 41 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
406 | 423 | | |
407 | | - | |
| 424 | + | |
408 | 425 | | |
409 | 426 | | |
410 | 427 | | |
| |||
810 | 827 | | |
811 | 828 | | |
812 | 829 | | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
817 | | - | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
818 | 843 | | |
819 | | - | |
| 844 | + | |
820 | 845 | | |
821 | 846 | | |
822 | 847 | | |
| |||
Lines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | | - | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
25 | 38 | | |
26 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
27 | 42 | | |
28 | 43 | | |
29 | 44 | | |
30 | 45 | | |
31 | 46 | | |
32 | 47 | | |
33 | 48 | | |
34 | | - | |
| 49 | + | |
35 | 50 | | |
36 | 51 | | |
37 | 52 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
233 | 251 | | |
234 | 252 | | |
235 | 253 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
| 288 | + | |
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| |||
0 commit comments