You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I was going through the packer.ex code and I noticed that list serialization (same goes for maps as well) is not as fast as it could be.
According to the erlang efficiency guide bitstrings are modeled as actual byte arrays underneath that double their size once they fill up. So appending to a binary should be more efficient than inserting in the middle and reallocating+copying over to a new binary for each list item.
To try this theory I added another option when packing (append: true) and benchmarked the existing code against the new using benchee
Name ips average deviation median
append 720.00 1388.89μs (±50.43%) 1600.00μs
normal 9.77 102344.83μs (±33.54%) 94000.00μs
Comparison:
append 720.00
normal 9.77 - 73.69x slower
Should I make a pull request for this? (I would remove the append option of course and make that the default code path)
The text was updated successfully, but these errors were encountered:
Hi, I was going through the packer.ex code and I noticed that list serialization (same goes for maps as well) is not as fast as it could be.
According to the erlang efficiency guide bitstrings are modeled as actual byte arrays underneath that double their size once they fill up. So appending to a binary should be more efficient than inserting in the middle and reallocating+copying over to a new binary for each list item.
To try this theory I added another option when packing (append: true) and benchmarked the existing code against the new using benchee
These are the relevant code changes:
instead of reversing the list leave it as is
and append instead of inserting in the middle
I then tested the performance using the following benchee snippet
which reported the following stats
Should I make a pull request for this? (I would remove the append option of course and make that the default code path)
The text was updated successfully, but these errors were encountered: