Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

throw away while loop in block & biome registry #198

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from

Conversation

granny
Copy link
Collaborator

@granny granny commented Oct 17, 2023

This greatly increases performance when registering an extremely large amount of blocks and biomes. Since this is the only place where we add to the indexMap, it's safe to increment it based on it's size. This change decreases the time for registering 9066 blocks from 20 minutes down to ~5 seconds.

This greatly increases performance when registering an extremely large amount of blocks and biomes. Since this is the only place where we add to the indexMap, it's safe to increment it based on it's size. This change decreases the time for registering 9066 blocks from 20 minutes down to ~5 seconds.
@BillyGalbreath
Copy link
Owner

BillyGalbreath commented Oct 23, 2023

i dont think this will work. its convoluted because it has to ensure previously registered blocks/biomes keep the same ids they originally generated.

take this for example:

0 air
1 stone
2 grass
3 sand
4 cobblestone

if we remove grass and then add logs, we end up with 2 blocks with the same id

0 air
1 stone
3 sand
4 cobblestone
4 logs

thats why i do it the slow way and check if the value (id) already exists in an infinite loop until one is found thats not been used, which would make logs use the now unused id of 2

@granny
Copy link
Collaborator Author

granny commented Oct 24, 2023

Alright, makes sense. I can put it back to my original fix, which was having the index as a private variable that gets incremented. The issue with the current code is that it'll start from 0, go through and check every block until one is found that's not been used, then goes back to 0 and checks the same indexes that it had checked already, which is redundant. That redundancy is what slows down not just pl3xmap, but the whole server.

I don't know why I didn't include this in the original PR body. Here's the log and spark link of a modified pl3xmap jar that outputs the blocks into the log as it registers them (i had copied the log call from the registerDefaultBlocks method to the register method and forgot to change "registering default block" to "registering block", which is why that shows in every log even though it's running from register)
https://mclo.gs/Q6QX5v2
https://spark.lucko.me/r5CmCgvKCH

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants