快速配方查找

快速配方查找

显著加快配方搜索速度。

性能

本模组最新版本需要在客户端和服务端同时安装(Fabric 版本除外)。

本模组大幅提升了配方查找速度。其核心机制是基于配方材料的哈希码构建树状索引,其中材料作为分支,配方作为节点。搜索时,先从容器中提取材料,并从根节点开始匹配;如果某个键不匹配,则直接剪除该分支,不再搜索,直到找到完全匹配的配方。这极大地减少了需要检查的配方数量。与原版逐一比较配方的方法相比,速度提升超过10倍,且配方总数越多,性能优势越明显。

兼容性:

本模组与所有使用原版配方管理器进行配方搜索的模组兼容。它与 Recipe Essentials(或 FastSuite)完全不兼容,因为它们优化了同一模块。根据我的测试结果,单独安装本模组效果最佳——在确保兼容性的同时提供了更优的优化性能。

Recipe Essentials 依赖缓存机制(通常性能不佳),而 FastSuite 使用并行处理(将性能开销分散到多个线程,并可能导致兼容性问题)。

FastFurnace、FastWorkbench、Client Crafting 均兼容。

配置: 由于部分模组以非标准方式实现配方相关接口——例如,它们实现了 Recipe 接口的 getIngredients 方法,因此可以提取材料并得到本模组的优化,但相应的 Container 接口未实现 getItem 方法,导致无法搜索该模组的配方。

为解决此问题,本模组默认只优化原版配方类型(工作台、熔炉等)。如果你需要更好的优化效果,可以尝试关闭“optimize_only_vanilla”选项。

性能分析

在原版中:

  • 配方搜索速度提升 8.36 倍至 85.95 倍
  • 大多数基础配方的提升幅度在 8-40 倍之间
  • 失败匹配的处理速度提升 28.11 倍

在 ATM9(大型整合包)中:

  • 提升效果更加显著,速度提升范围从 133.19 倍到 6942.47 倍
  • 像木棍和工作台这类基础配方的提升幅度超过 5000 倍

测试结果

原版

[19:27:59] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到金合欢木板配方的平均耗时 9130.97 ns [19:28:00] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到金合欢木板配方的平均耗时 85468.055 ns 差距:快 8.36 倍

[19:28:00] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到木棍配方的平均耗时 1149.77 ns [19:28:01] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到木棍配方的平均耗时 98866.69 ns 差距:快 85.95 倍

[19:28:01] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到工作台配方的平均耗时 989.36 ns [19:28:02] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到工作台配方的平均耗时 39704.348 ns 差距:快 40.14 倍

[19:28:02] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到黑色潜影盒配方的平均耗时 7168.7905 ns [19:28:03] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到黑色潜影盒配方的平均耗时 99736.78 ns 差距:快 13.91 倍

[19:28:03] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到失败匹配的平均耗时 3845.24 ns [19:28:04] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到失败匹配的平均耗时 108064.26 ns 差距:快 28.11 倍

ATM9

[20:05:20] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到金合欢木板配方的平均耗时 36147.832 ns [20:06:48] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到金合欢木板配方的平均耗时 8826844.0 ns 差距:快 244.16 倍

[20:06:48] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到木棍配方的平均耗时 2543.54 ns [20:09:20] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到木棍配方的平均耗时 1.5240665E7 ns 差距:快 5992.52 倍

[20:09:20] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到工作台配方的平均耗时 1175.53 ns [20:10:42] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到工作台配方的平均耗时 8158714.5 ns 差距:快 6942.47 倍

[20:10:42] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到黑色潜影盒配方的平均耗时 8131.2 ns [20:13:04] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到黑色潜影盒配方的平均耗时 1.4163565E7 ns 差距:快 1742.03 倍

[20:13:05] [Server thread/INFO] [fastrecipesearch/]: [Fast Test] - 找到失败匹配的平均耗时 128783.62 ns [20:15:57] [Server thread/INFO] [fastrecipesearch/]: [Default Test] - 找到失败匹配的平均耗时 1.7153812E7 ns 差距:快 133.19 倍