### Implement BlockState Neighbors with FastMap Source: https://github.com/malte0811/ferritecore/blob/26.1/summary.md Replaces vanilla's Table-based implementation for BlockState neighbors with a FastMap (an ArrayList used as a multi-dimensional array). This reduces memory usage from O((number of states) * sum(number of values per property)) to O(number of states). ```java In vanilla this is implemented using a Table, Comparable, S> for each state. In total these tables use about 600 MB of memory. Asymptotically (which is relevant for complex blocks in practice) the memory usage for a block is O((number of states) * sum(number of values per property)). By replacing these with one FastMap per block this can be reduced to O(number of states), with a similar coefficient. A FastMap in this case is simply an ArrayList used as a multi-dimensional array. Finding a neighbor state can be done by a few integer modulo, multiplication and addition operations. Alternatively it can be implemented using bitmasks, for slightly improved performance at slightly higher memory usage (this is the default starting in version 2.0). ``` -------------------------------- ### Optimize BlockState Property Storage Source: https://github.com/malte0811/ferritecore/blob/26.1/summary.md Replaces the ImmutableMap used for storing blockstate properties with a custom implementation based on FastMap. This significantly reduces memory usage compared to the default ImmutableMap. ```java Each blockstate stores its properties as an ImmutableMap, Comparable>, which takes around 170 MB in total. Replacing this ImmutableMap by a custom implementation based on the FastMap from the previous point (loaded with some classloader trickery) removes most of that memory usage. ``` -------------------------------- ### Avoid Capturing Optionals in Lambdas Source: https://github.com/malte0811/ferritecore/blob/26.1/summary.md Replaces an 'else' branch that returns a lambda capturing an Optional with one that unwraps the Optional first. This allows the Optional to be garbage collected sooner, saving memory. ```java Optional opt=newlyCreatedOptional(); if(!opt.isPresent()){ // Something }else{ return()->doThing(opt.get()); } ``` ```java T unwrapped = opt.get(); return () -> doThing(unwrapped); ``` -------------------------------- ### Cache Multipart Model Predicates Source: https://github.com/malte0811/ferritecore/blob/26.1/summary.md Caches multipart model predicates to reduce memory usage, especially for common cases like boolean properties. Predicates are cached using property/value pairs or sorted lists of input predicates as keys. ```java Each multipart model stores a number of predicates to determine which parts to show under what conditions. These predicates take up 300-400 MB. However in many cases these predicates are checking the same thing, they are just newly created every time. For KeyValueCondition the predicates can be cached by using the property and its value as a key, for And/OrCondition ( and multi-value KeyValueCondition s) the key is the list of input predicates sorted by hash value. One detail that makes this even more effective is that a block can never have two properties that are equal according to equals, while the common property implementations include equals. Additionally StateHolder#get also considers equals (as opposed to reference equality), so using the same lambda for equivalent (but non reference-equivalent) properties and values is actually possible. This is particularly useful as one of the most common usages of multipart models is pipes, where the states are nearly always boolean properties named north etc. As a result the number of predicates is reduced from between 10s of thousands and millions to a few ten or hundred instances. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.