p455w0rd / p455w0rds-Library

Stuff commonly used by my mods
MIT License
6 stars 7 forks source link

fix performance issues pertaining to light code, and more! (#33, #39) #43

Closed asiekierka closed 5 years ago

asiekierka commented 5 years ago

This greatly reduces the performance impact of p455word's Library mod without removing any functionality. As a friend asked me to fix this very nicely for his server, I decided to do so - let's go through the problems and changes quickly.

The Problems

This library mod adds a BlockGenEvent, which is emitted - according to the code - for every block loaded, generated, placed or broken. (This is very far from covering all cases of block changing, FWIW, but let's roll with it.) This, for a player join, amounts to about (16 x 16 x 256) x 200 = 13107200 (yes, 13 million) events emitted, and a 26 million BlockPos objects created along the way. Obviously, this alone takes a while.

The BlockGenEvent is only used, as far as I can tell, for one feature - handling colored lighting; that is, adding blocks to the list of "cached positions" for checking light information. I could spend hours arguing about the frivolity of sneaking in such a cosmetic feature with a potential high performance impact into a library mod, but as this is a technical pull request I'll try to stop myself from doing so. (The keyword being "try".)

The check for whether a block (or stack) is a light source involves two redundant instanceofs and one Pair<> object lookup. The lookup creates zero objects if a block (or stack) is a light source, and two objects if a block (or stack) is not a light source. Not ideal at all.

On top of that, debugging revealed that the names of "disable warnings" emitted by ClassTransformer are incorrect and misleading - if Albedo is detected, it warns that Sponge/Mixins have been detected; and vice versa.

The Changes

By the way, I also fixed some bugs pertaining to your handling of attachChunkLoader/detachChunkLoader.

Please don't push complex, lag-inducing features on users as part of a library mod.

asiekierka commented 5 years ago

A testing build is avaliable at https://asie.pl/files/p455w0rdslib-1.12.2-2.2.145-asie1.jar, pursuant to the terms of the MIT License.

p455w0rd commented 5 years ago

wish you would have contacted me prior and did work based on what I have locally...if you want to, you can find me easily on discord..thanks for putting time into this

asiekierka commented 5 years ago

@p455w0rd I would have loved to, but my friend needed a fix urgently, and I wasn't even aware the issue was reported before.

If you're not keeping the GitHub repository up to date, then consider doing so.

p455w0rd commented 5 years ago

yeah...unfortunately personal projects don't keep the lights on...if people want that to change, I have various ways of supporting me plastered everywhere..until then, personal stuff has to take a back seat...sorry