内存分配
某些类的内存占用非常高,它们具有较大的内存足迹。
这是一个问题,因为你的计算机只能将 64 字节放入处理器的缓存行中,因此超过 64 字节的内容需要被分割到多个行中。这会根据所调用的内容极大地降低操作速度。
因此,显然最好的解决方案是确保没有任何东西超过 64 字节,但这说起来容易做起来难,因为这有多重缺点,尽管在我优化的情况下这些缺点并不重要。
区块内存分配
区块的内存占用非常高,占据 80 字节。使用一些 hacky 的 fabric-ASM,我们能够从 Chunk 类中删除变量并重定向所有调用。
这使得我们可以将区块的大小重新降回 64 字节,在某些计算机上可以使大多数区块操作快 0.25 倍!
方块内存分配
方块的内存占用也非常高,占据 72 字节。
我们采取与区块相同的做法,将一些东西移入 BlockInfo 类并减少该类的重量。
这不仅使得大多数方块现在可以更快地传递,还防止了一些方块超过 128 字节,这将需要 3 个缓存行。
实体内存分配
与区块和方块不同,实体是一个噩梦。它占据 272 字节,即 5 个缓存行。难怪实体很卡顿 xD
我已经将其优化为 4 个缓存行,虽然再进一步会导致比我有时间修复的更多的模组兼容性破坏。
如果模组足够大,我可能会重写整个实体类,并为所需的值提供一个 API。
为什么 Mojang 不做这个?
嗯,他们好像在这样做?
在进行我的优化时,我注意到 Mojang 实际上已经做了与我相同性能改进。例如 LevelInfo,虽然那已经是几年前的事了?
Mojang 似乎对这些天的性能不太关心,他们做出了一些非常奇怪的性能更改,但似乎并不太在意。一些类在过去几年里增长了很多,他们没有真正注意到它们变得多么密集。
不过没关系,因为我是来帮忙的。
猫鼠游戏
获取更多性能很难,这是一个非常复杂的拼图,需要你深入了解每一个细节。
简而言之,计算机并不简单。他们试图让程序员更容易不去思考这一点,尽管程序员应该始终考虑到这一点。
我在说什么呢?
嗯,我通过此模组获得的性能是有代价的,额外的调用和内存分配。我只是在优化游戏内的结构以使其与计算机一起尽可能平滑快速地工作,但这需要计算机记住更多的事情。
不幸的是,你不会注意到这种成本,因为在大多数情况下,性能收益远远超过损失。
实验性!!!
看来我需要继续说它。这个模组高度实验性,并进行了一些超级 sketch ASM 魔法,通过简单地移动类来获得性能。不要将其包含在整合包中,也不要就兼容性问题提出 issue。这个模组是为了证明概念而制作的,看看我们是否可以通过减少缓存行中的类大小来进一步优化 Minecraft。这个模组显示了明显的性能提升,尽管它未经充分测试,并且仍然需要大量工作。我目前没有时间继续在这个模组上工作
Memory Allocation
Some classes can be very memory dense, they have a big memory footprint.
This is an issue because your computer can only fit 64 bytes into a processor's cache line, so anything over 64 needs to be split into multiple lines. This can drastically slow down operations based on what is being called.
So obviously the best solution is to make sure nothing is over 64 bytes, this is a lot easier said than done, since there's multiple downsides to this, although they don't matter in the circumstances that ive optimized.
Chunk Memory Allocation
Chunks are very memory dense and take up 80 bytes. Using some hacky fabric-ASM we are able to nuke variables from the Chunk class and redirect all the calls.
This allows us to bring the chunk back down to 64, which on some computers can make most chunk operations 0.25x faster!
Block Memory Allocation
Blocks are also very memory dense, taking up 72 bytes.
We do the same thing as Chunks, we move stuff into a BlockInfo class and reduce the weight of the class.
This not only makes it so most blocks can now be passed along faster, but also prevents some blocks from going over 128 bytes, which would need 3 cache lines.
Entity Memory Allocation
Unlike Chunk & Block, entity is its own nightmare. It takes up 272 bytes, which is 5 cache lines. No wonder entities are laggy xD
I've optimized it to 4 cache lines, although going any further will break more mod compatibility than I have the time to fix.
If the mod grows big enough at some point, I may rewrite the entire entity class and just provide an API for the values you would want.
Why is Mojang not doing this?
Well they kinda are?
When making my optimizations I noticed that mojang has actually made the same performance improvements that I'm doing. Such as LevelInfo, although that was years ago?
Mojang does not seem to care about performance much these days, they make really weird performance changes but never seem to really care too much. Some classes have grown a lot in the last years, and they haven't really noticed how dense they have become.
That's fine though, cause I'm here to help.
The game of cat and mouse
Performance is hard to get more of, it's a very complex puzzle which requires you to understand every single part of it in a lot of detail.
Put simply, computers are not simple. They try really hard to make it easier for the programmer to not think about it, although programmers should be thinking about it at all times.
What am I talking about?
Well the performance I get with this mod comes at a cost, extra calls and memory allocation. I'm simply optimizing the structures within the game to work as smoothly and quickly with the computer, although that requires the computer to remember more things.
Unfortunately, you won't notice that cost since in most of these situations the performance win greatly overcomes the loss.
Experimental!!!
Seems I need to continue saying it. This mod is highly experimental and does some super sketch ASM magic to gain performance by simply moving classes around. Do not include this in modpacks, and do not make issues about compatibility. This mod was made as a proof of concept to see if we could further optimize minecraft by reducing the classes sizes in the cache lines. This mod showed a clear performance win, although its pretty untested and still needs LOTS of work. I don't have time to continue working on this mod currently
评论 0
登录后参与评分
还没有评论,来抢沙发吧