-
-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve BiomeMask performance #3082
base: main
Are you sure you want to change the base?
Conversation
class BiomeTypeIdCache { | ||
private static final List<BiomeType> byId = create(); | ||
|
||
private static List<BiomeType> create() { | ||
BiomeType[] array = values().toArray(new BiomeType[0]); | ||
Arrays.sort(array, Comparator.comparing(BiomeType::getLegacyId)); | ||
return List.of(array); | ||
} | ||
|
||
} | ||
if (legacyId >= 0 && legacyId < BiomeTypeIdCache.byId.size()) { | ||
return BiomeTypeIdCache.byId.get(legacyId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any specific reason on using a List instead of an array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, the list is immutable and its backing array is marked stable which might help performance in some cases, but it likely doesn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think any performance drops from using a list should be compiled away given it's a static final list, so it should just act as an array in runtime
Overview
Description
BiomeMask and biome access generally are rather slow, and a lot of the slowness is caused by inefficient translation and slow contains checks. The adaption from NMS biomes to WE BiomeType can be simplified as we already set the legacy id (= NMS-internal id). The HashSet can be replaced by a boolean array, similar to how BlockMask works.
Submitter Checklist