Skip to content

Commit

Permalink
Specialize Dict's key to ByteArray
Browse files Browse the repository at this point in the history
  Looking at Aiken's repositories in the wild, no one is using Dict with
  anything else than ByteArray as key. The extra complexity we bring
  just for making it generic in the key argument seems not worth it.

  Plus, if we know the key is a ByteArray, we can perform some
  optimizations on a few functions looking for keys to short-circuit
  them instead of traversing a list entirely.

  Here's a comparison of the mem and cpu cost before and after the
  chance for a few tests (omitted tests have identical cost).

  | mem     | cpu     | bench                     |
  | ---     | ---     | ---                       |
  | -10.15% | -5.88%  | delete_3                  |
  | -4.00%  | -9.68%  | delete_4                  |
  | -3.80%  | -9.39%  | delete_5                  |
  | -31.03% | -42.88% | delete_6                  |
  | -15.26% | -26.34% | find_4                    |
  | -11.10% | -18.85% | from_list_2               |
  | -8.02%  | -16.26% | from_list_3               |
  | -12.15% | -25.39% | from_list_4               |
  | -19.24% | -36.11% | bench_from_list           |
  | -17.79% | -18.91% | bench_from_ascending_list |
  | -4.91%  | -10.58% | get_2                     |
  | -9.49%  | -14.63% | get_3                     |
  | -29.94% | -42.75% | get_4                     |
  | -23.66% | -37.70% | get_5                     |
  | -7.94%  | -5.03%  | has_key_3                 |
  | -9.97%  | -18.50% | has_key_4                 |
  | -16.46% | -23.61% | insert_1                  |
  | -16.52% | -26.24% | insert_2                  |
  | -13.82% | -22.08% | insert_with_1             |
  | -18.77% | -29.88% | insert_with_2             |
  | -19.12% | -30.52% | insert_with_3             |
  | -10.47% | -17.40% | keys_2                    |
  | 4.25%   | 5.06%   | map_1                     |
  | 2.94%   | 3.31%   | map_2                     |
  | -10.99% | -19.83% | size_3                    |
  | -7.94%  | -16.17% | union_1                   |
  | -17.74% | -28.17% | union_3                   |
  | -16.96% | -26.55% | union_4                   |
  | -15.91% | -25.10% | union_with_1              |
  | -10.47% | -17.39% | values_2                  |
  • Loading branch information
KtorZ committed Jan 14, 2024
1 parent 97cd613 commit 89b2e9f
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 315 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## UNRELEASED

### Changed

- Specialized all `Dict`'s key as `ByteArray`, and thus remove the need for passing an extra `bytearray.compare`.

## v1.7.0 - 2023-11-07

### Added
Expand Down
Loading

0 comments on commit 89b2e9f

Please sign in to comment.