perf(i18n): cache parametrised renders and reuse action snapshot factory - #128
Merged
Conversation
Spark sampling (j9YE2XtMP3) shows per-tick viewer rendering spends its time in MiniMessage deserialization under LocalizedMessages.plain with placeholder TagResolvers: - Cache Map-based render/plain by (locale, key, sorted placeholder entries) via Caffeine (max 512): hot paths publicSeatStatus, publicCenterText and botDisplayName now hit a single deserialize per stable placeholder set instead of per tick. - Add formatNumber + Map overloads to MessageService facade so hot callers can use the cached path without constructing TagResolvers. - Reuse one PlayerActionSnapshotFactory per session (was 3-4 news per bot tick) and replace hasAction stream().anyMatch with a plain loop. Behaviour is unchanged: placeholder maps are resolved by tag name, so iteration order does not affect output; bundles are immutable after load.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
BotActionSchedulerTest and SichuanBotPreparationSchedulerTest mock MahjongTableSession, which now exposes actionSnapshotFactory(). Stub it to return a real PlayerActionSnapshotFactory so the shared per-session factory path is exercised by the scheduler tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Spark 采样(https://spark.lucko.me/j9YE2XtMP3)显示每 tick 观众渲染大量时间花在
LocalizedMessages.plain的 MiniMessage 反序列化(renderWithTags/deserialize热点,MessageService.plain栈)与 G1 分配(allocate_new_tlab热点)上。三个改动(行为不变):
LocalizedMessages.render/plain(Locale, key, Map)现按(locale, key, 排序后的占位符条目)用 Caffeine(max 512)缓存;热路径publicSeatStatus/publicCenterText/botDisplayName每 tick 只对稳定占位符集反序列化一次。占位符按 tag 名解析,Map 迭代顺序不影响输出;bundle 加载后不可变。render/plain(Locale, key, Map)+formatNumber委托,热调用方无需构造 TagResolver 数组。GbBotStrategy.hasActionstream → for 循环。门禁
性能 label:
performance-ab+performance-i18n(i18n profile 为 PR-A #126 新增,含 bot-name / seat-status / center-text 等带占位符渲染基准)。Test plan
compileJava(JDK 25 toolchain)通过-PmahjongJavaTarget=25,getFirst 需要 Java 21+ API)