redruin1 / factorio-draftsman

A complete, well-tested, and up-to-date module to manipulate Factorio blueprint strings. Compatible with mods.
MIT License
94 stars 17 forks source link

Rewrite of the _shift_key_indices function to make if faster #26

Closed louga31 closed 2 years ago

louga31 commented 2 years ago

I rewrote the _shift_key_indices function using dictionary comprehension, to make it run a lot faster (from 21 seconds down to 4.7 on a big blueprint). This function was responsible for more than 75% of the time spent. (Total time got from 47 seconds down to 14) This was especially true for big blueprints with many entities. I ran the test suite and coverage, and all 396 tests passed. (I left the old code commented to make it easier to understand, as it's more verbose)

Before: image

After: image

redruin1 commented 2 years ago

Awesome, thanks. I've yet to set up any performance tests or analyze it rigorously, so if you find any other problem areas that you don't want to handle yourself, feel free make an issue for them and I'll take a look later on.

I should also probably make a formal contributing page, but the basic process is this: