Skip to content

Add performance improvements to core - #1596

Merged
eriksvedang merged 9 commits into
carp-lang:masterfrom
hellerve:perf/core
Oct 16, 2026
Merged

eriksvedang merged 9 commits into
carp-lang:masterfrom
hellerve:perf/core

Conversation

@hellerve

@hellerve hellerve commented Oct 9, 2026

Copy link
Copy Markdown
Member

this pr adds a bunch of performance improvements to core:

  1. String.starts-with? and String.ends-with? now compare bytes. They used to decode the whole string into chars, and now compare bytes and stop at the first mismatch. This also fixes (starts-with? "ölheller" "öl"), which returned false. I measured 9.4µs → 0.1µs on a 4KB string.
  2. Array.swap! now moves instead of copying, because it used to make two copies and two deletes per swap. Heapsort (one of the consumers) on 2k strings: 1.22ms → 0.36ms
  3. Map and Set now use open addressing, which was on our backlog for a while. Uses linear probing over a column of stored hashes, Fibonacci hashing, and removal without tombstones. Also, in-place operations grow the table, and the functional versions stop copying it. 10k int put!: 3.2ms → 59µs
  4. Semi-related: I moved Map.update-value! / Map.value-ref! into core from web,. They pass a reference to the stored value without copying it.
  5. String.split-by, slice, prefix, suffix/ split-by ran strlen on the whole string once per separator, so lines and words were accidentally quadratic. Also, slice decoded the whole string. Both are now single byte scans. lines on 90KB went from 18ms to 0.25ms.
  6. Array.map-reduce, slice, remove-nth: map-reduce copied its result array on every step. slice grew its result per element. remove-nth copied every element after nth. 10k map-reduce: 2.86ms → ~1µs
  7. For str on Map, Set, and Bag each entry used to copy the whole string built so far. They now collect the pieces and join them once. 1.68ms → 0.45ms on 2k-entry Map.str.

Added a whole bunch of tests.

Cheers

@hellerve

hellerve commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Added one more: Map.value-ref! can be used for Map.=! Faster and cleaner.

@hellerve
hellerve requested a review from eriksvedang October 10, 2026 21:18

@eriksvedang eriksvedang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very nice, thanks a lot for this!

@eriksvedang
eriksvedang merged commit f7dacbc into carp-lang:master Oct 16, 2026
4 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