📖 概览
这是一款客户端光照计算优化模组,通过缓存光照查询结果、优化区块构建期间的数据读取路径,并与 Sodium Dynamic Lights 集成以消除冗余计算,从而降低区块加载、相机旋转和大范围方块变化时的 CPU 开销。
简单来说:光照计算速度提升两倍,区块构建速度加快 49%,探索更加流畅,卡顿显著减少。
✨ 关键成果
基于 120 秒的 Spark A/B 测试,唯一变量为是否安装 LightStar:
| 指标 |
无 Lightstar |
有 Lightstar |
改进幅度 |
| 总光照计算时间 |
基准 |
-52.5% |
快 2 倍 |
| 光照处理吞吐量 |
1.0x |
2.1x |
+110.5% |
| Embeddium 区块构建吞吐量 |
1.0x |
1.49x |
+49% |
| 动态光照查询时间 |
82.3 s |
0.05 s |
-99.94% |
结果为两组测试(开启/关闭光影)的等权重平均值。
测试配置:AMD Ryzen 9 9950X3D + NVIDIA RTX 4080 Super OC。在实际使用中,中低端配置的改善效果会更加明显。
🎯 预期收益
- 减少 Embeddium 异步区块构建期间的冗余光照查询、坐标转换和数组清理操作。
- 减少在重复采样相同位置时的哈希查找和数组访问次数。
- 复用来自相同不可变区块快照的静态光照结果,降低重复区块构建的成本。
- 阻止不支持 Forge 外部面剔除的方块进入邻居面剔除查询。
- 当安装 Sodium Dynamic Lights 时,减少动态光照查询期间的冗余遍历、读写锁竞争和线程本地状态开销。
⚙️ 实现细节
光照缓存
使用四路组相联的线程本地原始类型缓存来存储最近的光照值,并为最常访问的位置提供额外的单条目快速路径。光照更新会推进数值生成计数器,立即使旧结果失效。DataLayer 的 nibble 读取使用直接索引和位运算,以减少热路径上的辅助方法调用和乘法运算。
Embeddium 区块构建
- 单次遍历同时读取方块光和环境光,消除了对同一坐标进行第二次区块段查找的需求。
- 方块光固定在低 4 位,环境光固定在高 4 位,消除对枚举顺序的依赖。
- 使用 16 位生成数组,而不是为每个构建任务清零所有 8000 个缓存槽位。
- 为克隆的不可变区块段分配数值修订版;仅在世界、原点以及所有区块段修订版匹配时,才跨任务复用缓存。
- 跨任务缓存采用按访问顺序淘汰策略,并在玩家登录/登出世界时清除。
Sodium Dynamic Lights 集成
- 动态光照查询状态和 4096 条目的四路组相联缓存由
ArrayLightDataCache 实例直接拥有,消除了 ThreadLocalMap 查找。
- 在每个构建任务开始时,在 SDL 读锁下复制动态光源引用的快照。任务内的查询直接迭代此快照,避免每次采样都获取
ReentrantReadWriteLock。
- 光源更新会推进生成计数器;移动的光源永远不会写入持久化缓存或留下静态残影。
- 非区块构建路径保留完整的 SDL 回退行为以确保兼容性。
⚠️ 不兼容项
- Starlight — 不兼容。
- Sodium/Embeddium Options API — 不兼容。本模组在此场景下毫无意义,且不是 Sodium Dynamic Lights 的必要依赖项。
📖 Overview
This is a client-side lighting computation optimization mod that reduces CPU overhead during chunk loading, camera rotation, and large-scale block changes by caching lighting query results, optimizing data read paths during chunk building, and integrating with Sodium Dynamic Lights to eliminate redundant computations.
In simple terms: lighting calculations are twice as fast, chunk building is 49% faster, exploration is smoother, and stuttering is significantly reduced.
✨ Key Results
Based on 120-second Spark A/B tests, with the only variable being the presence of LightStar:
| Metric |
Without Lightstar |
With Lightstar |
Improvement |
| Total lighting computation time |
Baseline |
-52.5% |
2x faster |
| Lighting processing throughput |
1.0x |
2.1x |
+110.5% |
| Embeddium chunk building throughput |
1.0x |
1.49x |
+49% |
| Dynamic light query time |
82.3 s |
0.05 s |
-99.94% |
Results are equally weighted averages from two test groups (shaders on/off).
Test Configuration: AMD Ryzen 9 9950X3D + NVIDIA RTX 4080 Super OC. In practice, lower-end and mid-range configurations will experience even more noticeable improvements.
🎯 Expected Benefits
- Reduces redundant lighting queries, coordinate conversions, and array cleanup during Embeddium's async chunk building.
- Reduces hash lookups and array accesses when sampling the same position repeatedly.
- Reuses static lighting results from identical immutable chunk snapshots, lowering the cost of repeated chunk builds.
- Prevents blocks that do not support Forge's external face culling from entering the neighbor face culling query.
- When Sodium Dynamic Lights is installed, reduces redundant traversal, read-write lock contention, and thread-local state overhead during dynamic light queries.
⚙️ Implementation Details
Lighting Caching
Uses a 4-way set-associative thread-local primitive cache to store recent lighting values, with an additional single-entry fast path for the most recently accessed location. Lighting updates advance a numeric generation counter, immediately invalidating old results. DataLayer nibble reads use direct indexing and bitwise operations to reduce helper method calls and multiplication on the hot path.
Embeddium Chunk Building
- Reads block light and sky light in a single pass, eliminating a second section lookup for the same coordinates.
- Block light is fixed in the lower 4 bits and sky light in the upper 4 bits, removing dependency on enum ordering.
- Uses a 16-bit generation array instead of zeroing out all 8000 cache slots for each build task.
- Assigns a numeric revision to cloned immutable sections; cross-task caching is reused only when the world, origin, and all section revisions match.
- Cross-task cache uses access-order eviction and is cleared on world login/logout.
Sodium Dynamic Lights Integration
- Dynamic light query state and a 4096-entry 4-way set-associative cache are directly owned by the
ArrayLightDataCache instance, eliminating ThreadLocalMap lookups.
- At the start of each build task, a snapshot of dynamic light source references is copied under the SDL read lock. Queries within the task iterate directly over this snapshot, avoiding
ReentrantReadWriteLock acquisition per sample.
- Light source updates advance a generation counter; moving light sources never write to persistent caches or leave static afterimages.
- Non-chunk-building paths retain full SDL fallback behavior for compatibility.
⚠️ Incompatibilities
- Starlight — Not compatible.
- Sodium/Embeddium Options API — Not compatible. This mod serves no meaningful purpose and is not a required dependency for Sodium Dynamic Lights.
评论 0
登录后参与评分
还没有评论,来抢沙发吧