JEIOptimizer
并行构建 JEI 的成分过滤索引 — 在大型整合包中可将服务器加入时间缩短多达 17 秒。
故事背景
我和朋友们在一个私人的 AllTheMods 服务器上游玩。每次断开连接、重启,或者“我去拿个零食”,都要面对长达 40 秒的 "正在加入世界…" 黑屏等待,而其他人已经在挖矿了。
受够了这种体验。于是我把周末花在了研读 JEI 的源代码上,而不是玩游戏。这个模组就是由此诞生的。
它的作用
当你连接到模组化服务器时,JEI 会从头开始重建整个物品搜索索引 — 因为服务器可能会提供自定义配方。在一个拥有约 50,000 种物品的 250 个模组的整合包中,这会在主线程上耗时 12 秒以上。你的客户端只是单纯地卡住不动。
JEIOptimizer 将 JEI 的 IngredientFilter 构建过程分布在多个工作线程上并行执行。每个搜索前缀(物品名称、模组 ID、标签、提示文本等)都拥有自己的线程,运行在独立的数据结构上 — 无竞争、无竞态条件、无风险。
实际测量数据
测试环境:250+ 模组的整合包(AE2、Mekanism、Create、Cobblemon、Apotheosis、AllTheCompressed 等)。Ryzen 5600X · 10 个工作线程 · NVMe 固态硬盘 · 分配 8 GB RAM · 远程服务器(Hetzner 数据中心)。
| 阶段 |
原版 JEI |
+ JEIOptimizer |
缩减幅度 |
| 构建成分过滤索引 |
12.00 秒 |
0.79 秒 |
−94% (速度快 15 倍) |
| JEI 启动总计 |
25.84 秒 |
14.17 秒 |
−45% |
| 总连接时间 |
约 40 秒 |
约 23 秒 |
−42% (减少 17 秒) |
结合下面的额外优化技巧(见 再白嫖 8 秒),你可以将服务器连接时间稳定地从 40 秒降至约 23 秒。
工作原理(技术细节)
JEI 的 IngredientFilter 构建一个搜索索引,其中每个“前缀”(名称、modId、标签、提示文本等)都有自己独立的 GeneralizedSuffixTree。独立的结构意味着可以安全地并行构建。
原版 JEI:
遍历每种成分 (50,000种):
遍历每个前缀 (7-10个):
计算令牌 → 插入后缀树
单线程 = 约 12 秒。
JEIOptimizer:
对前缀进行并行流处理:
遍历每种成分:
计算令牌 → 插入各自的后缀树
6-10 个核心同时处理 7-10 个前缀 = 约 0.8 秒。
配置中的过滤模式
OFF — 原版 JEI 行为
BATCH — 小幅度的缓存友好型改进,单线程执行
PARALLEL_PREFIX — 按前缀并行构建(安全)
PARALLEL_FULL — 同时也对前缀内的令牌化进行并行处理(默认值,速度最快)
再白嫖 8 秒(手动 JEI 优化)
在 config/jei/jei-client.ini 中,修改:
tooltipSearchMode = DISABLED
JEI 会在每次连接时为所有物品的提示文本建立索引。某些模组在渲染提示文本时会进行大量的 I/O 操作 — 白白消耗掉最初那 12 秒中的约 8 秒。玩家几乎总是通过名称搜索,而不是提示文本。
如果玩家希望通过 #prefix 使用提示文本搜索,请改用 REQUIRE_PREFIX。
配置
config/jeioptimizer-client.toml(自动生成):
[filter]
mode = "PARALLEL_FULL" # 默认值。安全,速度最快。
async = false # 实验性功能:在后台构建
log_timing = true # 记录耗时以进行验证
worker_count = 0 # 0 = 自动 (核心数 - 2)
[plugins]
parallel_phases = [] # 实验性功能 — 见下文
parallel_creative_tabs = false # 实验性功能 — 见下文
</code></pre>
<p><strong>开箱即用的安全默认值。</strong>将 jar 文件放入 mods 文件夹即可,无需任何配置修改。</p>
<hr>
<h2 id="compatibility">兼容性</h2>
<ul>
<li><strong>Minecraft:</strong>1.21.1</li>
<li><strong>Mod loader:</strong>NeoForge 21.x</li>
<li><strong>JEI:</strong>19.x(适用于 1.21.1 的版本)</li>
<li><strong>Side:</strong>仅客户端 — 无需在服务器安装</li>
</ul>
<hr>
<h2 id="what-this-wont-speed-up">此模组无法加速的内容</h2>
<p>诚实地说明适用范围:</p>
<ul>
<li>❌ 游戏启动(模组构建、模型烘焙、资源包重载)</li>
<li>❌ 服务器数据同步(配方、标签、注册表)— 受限于网络和模组序列化</li>
<li>❌ 各模组的运行时数据重新生成 — Create 每次连接时生成 2,124 个配方,Cobblemon 会重新同步所有化石/标记/浆果,Apotheosis 会重新加载所有词缀。这些属于模组设计层面的选择。</li>
</ul>
<p>JEIOptimizer 将 <strong>JEI</strong> 从瓶颈中移除。它不再是那个“最长的木桶”,其他模组仍会按各自的方式运行。</p>
<hr>
<h2 id="experimental-features-default-off">实验性功能(默认关闭)</h2>
<p>经过测试,但在实际整合包中发现会导致问题。为精心挑选模组组合的用户提供可选开启:</p>
<ul>
<li><strong><code>plugins.parallel_phases</code></strong> — 并行插件配方注册。许多 JEI 插件(如 Theurgy、Ars Nouveau、Compact Machines)并非线程安全,会导致崩溃。</li>
<li><strong><code>plugins.parallel_creative_tabs</code></strong> — 并行创造模式标签页构建。许多模组以非线程安全的方式缓存标签页状态;在我们的测试中,22% 的 JEI 物品丢失。</li>
<li><strong><code>filter.async</code></strong> — 在后台构建过滤器;玩家可更早进入世界。如果他们在前 2 秒内打开 JEI,他们会看到直到就绪前的空白网格。</li>
</ul>
<p>除非你清楚自己在做什么,否则请保持关闭。</p>
<hr>
<h2 id="faq">常见问题</h2>
<p><strong>问:这会破坏 JEI 搜索功能吗?</strong> 默认模式(<code>PARALLEL_FULL</code>)改变了索引的<em>构建方式</em>,而非<em>内容</em>。物品、配方和搜索结果完全相同。</p>
<p><strong>问:我的整合包较小,收益会减少吗?</strong> 是的。当物品数量低于约 10,000 时,提升微乎其微。本模组专为拥有 30,000+ 物品的整合包设计。</p>
<p><strong>问:为什么不向 JEI 提交 PR?</strong> 也许以后会。Mezz(JEI 的作者)历来倾向于保守的更改 — 核心代码中的并行化可能不被欢迎。本模组的存在是为了让你不必等待上游更新。</p>
<p><strong>问:需要安装在服务器上吗?</strong> 不需要。纯客户端 mixin。将其放在服务器的 <code>mods/</code> 目录中不会产生任何效果(no-op)。</p>
<p><strong>问:它与 EMI / REI 兼容吗?</strong> 不,本模组专门针对 JEI。EMI 拥有自己的架构(且本身已经很快)。</p>
<hr>
<h2 id="credits">致谢</h2>
<p>已在自定义 250+ 模组整合包以及 AllTheMods10、AllTheMons 上测试通过。</p>
<p>感谢 <strong>Mezz</strong> 保持 JEI 源码开源且足够易读,以便从外部进行优化。</p>
<hr>
JEIOptimizer
Builds JEI's ingredient filter index in parallel — cuts server join time by up to 17 seconds on large modpacks.
The story
I was playing on a private AllTheMods server with friends. Every disconnect, every restart, every "let me grab a snack" meant 40 seconds of staring at "Joining world…" while everyone else was already mining.
Got tired of it. Spent a weekend with JEI's source code open instead of playing the game. This mod is what came out.
What it does
When you connect to a modded server, JEI rebuilds its entire item search index from scratch — because the server may ship custom recipes. On a 250-mod pack with ~50,000 items, this takes 12+ seconds on the main thread. Your client just sits frozen.
JEIOptimizer parallelizes JEI's IngredientFilter build across worker threads. Each search prefix (item name, mod ID, tag, tooltip, …) gets its own thread, running on independent data structures — no contention, no races, no risks.
Real-world measurements
Tested on a 250+ mod pack (AE2, Mekanism, Create, Cobblemon, Apotheosis, AllTheCompressed, …). Ryzen 5600X · 10 worker threads · NVMe · 8 GB RAM allocated · remote server (Hetzner DC).
| Phase |
Vanilla JEI |
+ JEIOptimizer |
Reduction |
| Building ingredient filter |
12.00 s |
0.79 s |
−94% (15× faster) |
| Starting JEI total |
25.84 s |
14.17 s |
−45% |
| Total connect time |
~40 s |
~23 s |
−42% (−17 s) |
Combined with the bonus tweak below (see Free 8 more seconds), you can drop server connect from 40 s → ~23 s consistently.
How it works (technical)
JEI's IngredientFilter builds a search index where each "prefix" (name, modId, tag, tooltip, …) has its own GeneralizedSuffixTree. Independent structures → safe to build in parallel.
Vanilla JEI:
for each ingredient (50,000):
for each prefix (7-10):
compute tokens → insert into suffix tree
One thread = ~12 seconds.
JEIOptimizer:
parallelStream over prefixes:
for each ingredient:
compute tokens → insert into own suffix tree
6-10 cores doing 7-10 prefixes simultaneously = ~0.8 seconds.
Filter modes (in config)
OFF — vanilla JEI behavior
BATCH — small cache-friendly improvement, single-threaded
PARALLEL_PREFIX — parallel per-prefix build (safe)
PARALLEL_FULL — also parallelizes tokenization within prefix (default, fastest)
Free 8 more seconds (manual JEI tweak)
In config/jei/jei-client.ini, change:
tooltipSearchMode = DISABLED
JEI indexes the tooltip text of every item on every connect. Some mods do heavy I/O in tooltip rendering — eating ~8 of those original 12 seconds for nothing. Players almost always search by name, not tooltip text.
If players want tooltip search via #prefix, use REQUIRE_PREFIX instead.
Configuration
config/jeioptimizer-client.toml (auto-generated):
[filter]
mode = "PARALLEL_FULL" # Default. Safe, fastest.
async = false # Experimental: build in background
log_timing = true # Log timings for verification
worker_count = 0 # 0 = auto (cores - 2)
[plugins]
parallel_phases = [] # Experimental — see below
parallel_creative_tabs = false # Experimental — see below
Safe defaults out of the box. Drop the jar in, you get the win. No config touching required.
Compatibility
- Minecraft: 1.21.1
- Mod loader: NeoForge 21.x
- JEI: 19.x (1.21.1 builds)
- Side: Client-only — server installation not needed
What this WON'T speed up
Being honest about scope:
- ❌ Game launch (mod construction, model baking, resource pack reload)
- ❌ Server data sync (recipes, tags, registries) — network and mod serialization bound
- ❌ Per-mod runtime data regen — Create generates 2,124 recipes every connect, Cobblemon resyncs all fossils/marks/berries, Apotheosis reloads all affixes. These are mod-design choices.
JEIOptimizer removes JEI from the bottleneck. It's no longer the long pole — other mods still do their thing.
Experimental features (default OFF)
Tested but found to break things on real mod packs. Available as opt-in for those with carefully chosen mod sets:
plugins.parallel_phases — Parallel plugin recipe registration. Many JEI plugins (Theurgy, Ars Nouveau, Compact Machines) are not thread-safe and crash.
plugins.parallel_creative_tabs — Parallel creative tab build. Many mods cache tab state non-thread-safely; in our test 22% of JEI items were lost.
filter.async — Builds filter in background; player enters world sooner. If they open JEI in the first 2 seconds, they see an empty grid until ready.
Leave these off unless you know what you're doing.
FAQ
Q: Will this break JEI search? Default mode (PARALLEL_FULL) changes how the index is built, not what. Same items, same recipes, same search results.
Q: I have a smaller modpack. Will I see less benefit? Yes. Below ~10,000 items the gain is marginal. Designed for 30k+ item packs.
Q: Why not submit a PR to JEI? Maybe later. Mezz (JEI's author) historically prefers conservative changes — parallelism in core code may not be welcomed. This mod exists so you don't have to wait for upstream.
Q: Server-side install needed? No. Pure client-side mixin. Putting it in mods/ on a server is a no-op.
Q: Does it work with EMI / REI? No, this targets JEI specifically. EMI has its own architecture (and is already fast).
Credits
Tested on a custom 250+ modpack and AllTheMods10, AllTheMons.
Thanks to Mezz for keeping JEI's source open and readable enough to optimize from the outside.
评论 0
登录后参与评分
还没有评论,来抢沙发吧