Ixeris
概述
Ixeris 是一个通过优化事件轮询来提升客户端性能的模组。
你可能已经注意到,在移动鼠标时帧率会出现明显的下降。部分帧率下降是因为游戏在旋转视角时需要执行额外的任务,例如计算区块的可见性。然而,由于原生代码中事件轮询的效率低下以及 JNI 向上调用(upcall)的开销,一些本可用于渲染的 CPU 时间被不必要地消耗在了事件轮询上。这在 Windows 系统上尤为明显,尤其是当你的鼠标拥有高轮询速率时。
Ixeris 主要通过以下两项措施来解决该问题:
- 线程化事件轮询。Ixeris 不再在同一线程上同时执行渲染和事件轮询,而是在 主线程 上进行事件轮询,并将渲染任务分发到单独的 渲染线程。
- 缓冲原始输入(仅限 Windows)。将用于输入轮询的方法从效率低下的
GetRawInputData(每个输入事件一次调用)切换为GetRawInputBuffer,后者允许批量读取原始输入消息(所有事件仅需一次调用)。此外,在 Java 代码中执行此工作使我们能够消除 JNI 向上调用的开销。
基准测试
这些测试均在世界完全加载且帧率稳定后进行。
测试 1:游戏内
此测试比较鼠标被捕获(即光标不可见)时的性能。测试在一个没有任何实体的超平坦世界中执行。
本测试在 Windows 上进行,Ixeris 默认使用缓冲原始输入以提升性能。“Ixeris, Non-buffered”列显示了禁用该选项时的帧率。
| 轮询速率 | 无 Ixeris | Ixeris, Non-buffered | Ixeris, Buffered |
|---|---|---|---|
| 8000 Hz | 12 FPS | 83 FPS (6.9倍) | 121 FPS (10.1倍) |
| 2000 Hz | 76 FPS | 114 FPS (1.50倍) | 135 FPS (1.78倍) |
| 500 Hz | 134 FPS | 145 FPS (1.08倍) | 151 FPS (1.13倍) |
测试 2:菜单界面
此测试比较鼠标未被捕获(即光标可见,如 F3+Esc 暂停屏幕)时的性能。在这种情况下,从不使用原始输入,因为游戏需要知道光标的 实际 位置,而非原始的相对移动量。轮询速率为 1000Hz。
“Idle FPS”列显示未移动鼠标时的帧率,接下来两列分别显示在没有 Ixeris 和有 Ixeris 的情况下,在游戏窗口内快速移动鼠标时的帧率。请注意,此测试是在 Ixeris 初始发布时进行的,此后已进行了许多改进。
| 空闲帧率 | 无 Ixeris | 有 Ixeris | |
|---|---|---|---|
| Windows | 233 FPS | 133 FPS | 165 FPS (1.24倍) |
| Linux (X11) | 358 FPS | 320 FPS | 355 FPS (1.11倍) |
| Linux (Wayland) | 364 FPS | 289 FPS | 298 FPS (1.03倍) |
技术细节
线程安全
在当前状态下,Ixeris 不会破坏线程安全性。通过 glfwSet*Callback 注册的回调在渲染线程上执行。对于必须在主线程上调用的 GLFW 函数调用,如果在其他线程上发起,会被分发到主线程。如果这些调用可以安全延迟,它们可能会立即返回;否则,调用者可能会被阻塞,直到调用完成。
自版本 3.1.0 起,严格遵循 GLFW 文档中的线程安全要求。
GLFW 状态缓存
大多数 GLFW 函数必须从主线程调用。然而,许多模组可能会从渲染线程调用它们。为了避免线程通信带来的性能下降,Ixeris 缓存了常用的 GLFW 状态,以便从任何线程快速访问,而无需将调用路由到主线程。这些缓存是安全的,不会引入额外延迟。
增强型帧率限制器
原版帧率限制器(26.1 之前)存在缺陷,它使用 glfwWaitEventsTimeout 进行休眠。然而,该函数不能从渲染线程调用,因此与 Ixeris 配合时无法达到最佳效果。
Ixeris 以混合方式重写了帧率限制器,精确休眠,并在等待时间极短时启动自旋等待。
术语表
- 主线程:游戏启动所在的线程。大多数 GLFW 函数必须在此线程上调用,并且它负责事件轮询。
- 渲染线程:执行游戏通常所做的所有操作,但不包括事件轮询。
这两个术语在原版的 Minecraft 中是同义的。
Ixeris
Overview
Ixeris is a mod that optimizes event polling to improve client performance.
You might have noticed a visible drop of the FPS when you move your mouse. Part of the FPS drop is because the game does have additional jobs to do when you turn the camera, like calculating the visibility of chunks. However, because of the inefficiency in the native code that polls events and the JNI upcall overhead, some of the CPU time, otherwize can be utilized for rendering, are unnecessarily spent on event polling. This is most noticeable on Windows, especially when your mouse has a high polling rate.
Ixeris resolves the issue mainly through two measures:
- Threaded Event Polling. Instead of performing rendering and event polling on the same thread, Ixeris performs event polling on the main thread and kicks rendering to a separate render thread.
- Buffered Raw Input (Windows-only). Switches the method used for input polling from the inefficient
GetRawInputData(one call for each input event) toGetRawInputBufferwhich allows reading raw input messages in batches (one call for all events). Additionally, performing this work in Java code has allowed us to eliminate the JNI upcall overhead.
Benchmarks
These tests are done after the world has fully loaded and the framerate has stabilized.
Test 1: In Game
This test compares the performance when the mouse is grabbed, i.e. cursor invisible. This test is performed in a superflat world with no entities.
This test is done on Windows, where Ixeris uses buffered raw input by default to improve performance. The "Ixeris, Non-buffered" column shows the FPS with that option disabled.
| Polling Rate | Without Ixeris | Ixeris, Non-buffered | Ixeris, Buffered |
|---|---|---|---|
| 8000 Hz | 12 FPS | 83 FPS (6.9x) | 121 FPS (10.1x) |
| 2000 Hz | 76 FPS | 114 FPS (1.50x) | 135 FPS (1.78x) |
| 500 Hz | 134 FPS | 145 FPS (1.08x) | 151 FPS (1.13x) |
Test 2: In Menus
This test compares the performance when the mouse is not grabbed, i.e. cursor visible, as in F3+Esc pause screen. In this case, raw input is never used as the game needs to know the actual cursor position, not the raw relative movement. The polling rate is 1000Hz.
The "Idle FPS" column shows the FPS when not moving the mouse, and the next two columns show the FPS when moving the mouse quickly over the game window, without Ixeris and with Ixeris, respectively. Note that this test was performed at the initial release of Ixeris, and many improvements have been made since then.
| Idle FPS | Without Ixeris | With Ixeris | |
|---|---|---|---|
| Windows | 233 FPS | 133 FPS | 165 FPS (1.24x) |
| Linux (X11) | 358 FPS | 320 FPS | 355 FPS (1.11x) |
| Linux (Wayland) | 364 FPS | 289 FPS | 298 FPS (1.03x) |
Technical Details
Thread Satefy
In its current state Ixeris should not break thread safety. Callbacks registered with glfwSet*Callback are executed on the render thread. Calls to GLFW functions that are required to be called on the main thread, if made on other threads, are dispatched to the main thread. These calls may immediately return if they can be safely delayed, or otherwise may block the caller until the call is finished.
As of version 3.1.0, the requirements of thread safety in the GLFW documentation are strictly obeyed.
GLFW State Caching
Most GLFW functions are required to be called from the main thread. However, many mods may call them from the render thread. To avoid performance degradation introduced by thread communications, Ixeris caches frequently used GLFW states for fast access from any thread, without having to route the call to the main thread. The caches are safe and do not introduce extra lag.
Enhanced FPS Limiter
The vanilla FPS limiter (prior to 26.1) is flawed, using glfwWaitEventsTimeout to sleep. This function, however, cannot be called from the render thread and thus does not work optimally with Ixeris.
Ixeris rewrites the FPS limiter in a hybrid way, sleeping precisely and starting spin waiting when the wait time is very low.
Glossary
- The main thread is the thread that the game is started on. Most GLFW functions are required to be called on this thread, and it is responsible for event polling.
- The render thread does everything the game normally does, except event polling.
These two terms are synonymous in vanilla Minecraft.
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Ixeris
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
- 修复了 SDL 上的拖放功能
- 修复了捆绑库的阴影问题。这是 4.6.9 版本中的回归问题,会导致启动失败。
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
原版世界生成优化模组
模组
内存使用优化
模组
一堆修复
模组
专为独立/集成服务器设计的优化模组。
模组
使用异步路径追踪来隐藏不可见的方块/实体
模组
一款旨在提升 Minecraft 区块性能的 Fabric 模组。
评论 0
登录后参与评分
还没有评论,来抢沙发吧