Skip to content

Latest commit

 

History

History
89 lines (60 loc) · 2.39 KB

PERFORMANCE.md

File metadata and controls

89 lines (60 loc) · 2.39 KB

TODO: create a video and delete this file

Performance Optimization

There's some neat tricks used to improve the performance of the mod, here's an overview :D

Minimum Tick Rate

The minimum timer interval of 1 second makes crappy programs 20x more performant since they aren't running every tick.

Pattern Caching

map from string to lambda

Be not afraid, regular expressions are only used when necessary.

string equals used when possible


Using the EACH keyword to count by type rather than by matcher also employs a cache.

EVERY 20 TICKS DO
    INPUT 2 EACH *ingot* FROM a
    OUTPUT TO b
END

This program will internally enumerate the registry to create a separate tracker for each resource type.

hashmap inspection of a map to lists with three keys

Object Pooling

EVERY 20 TICKS DO
    INPUT FROM a
    OUTPUT TO b
END

When many inventories are involved, this can quickly result in a lot of objects being created when the program runs.

625 barrels

My testing shows that object pooling provides a slight increase in performance, even if there's only tens of thousands of objects involved.

Testing

I created a custom barrel block used only for testing. Running all the game tests for the mod creates 2,866 barrel blocks. Many of those barrels are so full of items that when I clear or restart the tests it causes 27,310 stacks to be dropped on the ground.

By creating a custom barrel that doesn't drop the inventory contents, the friction of doing more tests is reduced!

tests

User Empowerment

NAME "first"
EVERY 20 TICKS DO
    INPUT FROM a
    OUTPUT TO b
END
NAME "second"
EVERY 20 TICKS DO
    INPUT stone, iron_ingot FROM a
    OUTPUT TO b
END

Which program is more efficient? idk. Use the performance graph and compare.

in-game performance gui in-game performance gui

Cool. Looks like the first one is twice as fast. Maybe you need to filter items though? Maybe the outcome is different if depending on the inventories?

Rather than trying to prescribe a best approach based on how I know the mod works, it's better to directly give the players the tools needed to perform experiments to find out what works best in their scenario.