Skip to content

optimize Hashtbl.replace -> Hashtbl.add#596

Merged
filipeom merged 3 commits intoformalsec:mainfrom
redianthus:hashtbladd
Apr 13, 2026
Merged

optimize Hashtbl.replace -> Hashtbl.add#596
filipeom merged 3 commits intoformalsec:mainfrom
redianthus:hashtbladd

Conversation

@redianthus
Copy link
Copy Markdown
Contributor

@redianthus redianthus commented Apr 13, 2026

This was showing up a little bit too much in my measurements (the one in expr.ml but I thought changing the others would do no harm).

EDIT: in the end I went with removing the Hashtbl, using a list is fine because 1. we never need to concatenate two lists, as we simply add one symbol at a time and 2. we can simply use List.sort_uniq at the end, which should be fine as there shouldn't be too many symbols.

@redianthus redianthus requested a review from a team as a code owner April 13, 2026 02:36
Copy link
Copy Markdown
Member

@filipeom filipeom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it because Hashtbl.add is faster in the happy path?

@redianthus
Copy link
Copy Markdown
Contributor Author

redianthus commented Apr 13, 2026

Yes, if you look at the implementation in the stdlib you'll see it is doing much less work (or maybe it's not in the happy path but simply becaus ewe have collisions and in this case, add is also better than replace).

Copy link
Copy Markdown
Member

@filipeom filipeom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool thanks!

@filipeom filipeom merged commit 4c509f6 into formalsec:main Apr 13, 2026
18 of 19 checks passed
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