Skip to content

CPU optimization of model/json#503

Merged
TomWright merged 10 commits intoTomWright:masterfrom
imix:optimize
Jan 20, 2026
Merged

CPU optimization of model/json#503
TomWright merged 10 commits intoTomWright:masterfrom
imix:optimize

Conversation

@imix
Copy link
Copy Markdown
Contributor

@imix imix commented Jan 16, 2026

Hi

I tried some optimization techniques on dasel and got some improvements.

One of the improvement stems from switching the json library which is maybe not desired. Nevertheless I left the other json library in the pull request to illustrate the potential.

My benchmark was as follows:
cat citylots.json | ./main_orig -i json "features.map(properties.MAPBLKLOT)"

with this json: https://github.com/zemirco/sf-city-lots-json

The version I started with measured as follows (using hyperfine):

Benchmark 1: ./test.sh
Time (mean ± σ): 17.369 s ± 0.032 s [User: 38.968 s, System: 1.464 s]
Range (min … max): 17.324 s … 17.422 s 10 runs

The optimized version had these results:

Benchmark 1: ./test.sh
Time (mean ± σ): 8.440 s ± 0.016 s [User: 14.793 s, System: 1.105 s]
Range (min … max): 8.417 s … 8.472 s 10 runs

Hope this helps or at least gives some insights.

@TomWright
Copy link
Copy Markdown
Owner

Hey @imix,

This is great, love to see a contribution like this.
I'll do my best to review and merge over the weekend.

@TomWright
Copy link
Copy Markdown
Owner

Hey @imix,

Could I ask you to separate the JSON change into a new PR please? Otherwise it's looking good

@imix
Copy link
Copy Markdown
Contributor Author

imix commented Jan 19, 2026

Hi @TomWright

I reverted the json library in this PR. I will create a second PR with the json library

@TomWright
Copy link
Copy Markdown
Owner

I've pulled in new tests for the IsScalar func and the null value doesn't appear to be handled

@TomWright
Copy link
Copy Markdown
Owner

I've adjusted the code - it can still likely be improved since we still use isNull, but this still provides a solid improvement:

time cat citylots.json | ./dasel_old.exe -i json 'features.map(properties.MAPBLKLOT)'

21.4s
19.6s
19.2s
18.6s
19.3s

time cat citylots.json | ./dasel_new.exe -i json 'features.map(properties.MAPBLKLOT)'

14.7s
14.8s
15.1s
14.5s
15.2s

I'll merge this here but of course welcome any further improvements.

Thanks for the contribution.

@TomWright TomWright merged commit cbc45b7 into TomWright:master Jan 20, 2026
14 checks passed
@imix
Copy link
Copy Markdown
Contributor Author

imix commented Jan 21, 2026

Great to see you could implement it! I did not find other big optimization areas so far. Maybe I have a look at Profile-guided optimization if I find the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants