-
Notifications
You must be signed in to change notification settings - Fork 527
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
Factorio: use orjson #1809
Factorio: use orjson #1809
Conversation
to sum up what i said in discord, i see two things:
|
|
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.
Generated spoiler for the same seed is identical between main and orjson.
Speed Improvement: 43% for all of factorio
$ python -m timeit 'import orjson; [orjson.loads(open(f"data/{f}.json").read()) for f in ("fluids","items","machines","recipes","resources","techs")]'
1000 loops, best of 5: 258 usec per loop
$ python -m timeit 'import json; [json.loads(open(f"data/{f}.json").read()) for f in ("fluids","items","machines","recipes","resources","techs")]'
500 loops, best of 5: 454 usec per loop
However it should be noted that, as long as we only use it for factorio, the switch has a negative impact:
- it is not builtin (i.e. not shared between different venvs), using up cache and taking longer1 to load
- it uses ~10MB of RAM, which is a fair trade-off if we use it in more places
$ python -m timeit 'import orjson; orjson.loads(open("data/fluids.json").read())'
20000 loops, best of 5: 10.3 usec per loop
$ python -m timeit 'import json; json.loads(open("data/fluids.json").read())'
20000 loops, best of 5: 11.8 usec per loop
EDIT: the 10MB figure includes all of its dependencies, so the actual impact is smaller. If we use fragments, we also win back (some) of the extra memory.
Footnotes
-
loading a single, small file gives almost no improvement: ↩
Re EDIT above: I remeasured |
* Factorio: use orjson * Factorio: update orjson --------- Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
* Factorio: use orjson * Factorio: update orjson --------- Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
What is this fixing or adding?
trial run of the orjson json library in Factorio
How was this tested?
running Generate with Factorio involved.
If this makes graphical changes, please attach screenshots.