Skip to content

Numbers overhaul - #4332

Open
kddnewton wants to merge 13 commits into
mainfrom
numbers
Open

kddnewton wants to merge 13 commits into
mainfrom
numbers

Conversation

@kddnewton

Copy link
Copy Markdown
Collaborator

Fixes #4319

A bunch of stuff in this one that I've wanted for quite some time.

  • Integer fields get smaller. Instead of size_t length; bool negative; uint32_t *values; uint32_t value; we get uint32_t length; bool negative; union { uint32_t value[2]; uint32_t *values; }. This means 64-bit integers can fit in the immediate and don't get allocated. It also means integers go from 20 bytes to 16 bytes, which also impacts rationals doubly.
  • We now have a fast path for parsing integers up to 64-bits in length that goes through schoolbook multiplication. After that if it's a power of 2 base we'll allocate directly into the buffer and parse directly. If it's decimal and below a certain threshold of words we'll use bignum schoolbook multiplication. After that threshold we'll still use karatsuba for the pathological case (it flips around 20K digits).
  • We now have a fast path for parsing rationals, and reduce automatically on all sizes. This means we never leave rationals unreduced, and it's orders of magnitude faster.
  • We now have a fast path for printing integers, and only rely on karatsuba when it makes sense.
  • We now parse floats ourselves, so we get rid of the old dance with libc where we check errno, allocate, check locale, do a bunch of work to make sure everything is safe, before finally handing over to strtod. Now instead we just do it ourselves, and actually route around some sharp edges that libc seems to have, especially on macOS. This one actually starts to get worse around exp +-200, but is quite a bit faster on all other cases.

Overall, integer parsing gets about 2x faster, rational parsing about 1.8x faster, short float parsing about 2x faster, and integer printing about 3x faster. We drop retained memory through this as well as the whole AST gets smaller whenever theres an integer or a rational.

This branch has not been deployed

No deployments
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.

Regression: IntegerNode values are incorrect after syntax errors

1 participant