Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor float parsing #510

Merged
merged 2 commits into from
Aug 10, 2023
Merged

Refactor float parsing #510

merged 2 commits into from
Aug 10, 2023

Conversation

jcrist
Copy link
Owner

@jcrist jcrist commented Aug 10, 2023

This refactors the number parsing routine (str -> int/float), with the following results:

  • Improved performance, up to 20% faster, dependent on message. This is most prominent for floats or long ints.
  • Ability to reuse the same routine for converting strings to ints or floats (or int/float-like things). Previously we had a duplicate str -> int routine, and relied on cpython's float parser for the str -> float conversions. With this change we're able to delete a bunch of code.
  • Expanded features. In particular, we can now support float-like strings as dict keys in JSON.
  • Improved maintainability. The reorganized code should provide a better base to build new features off of.

This also adds support for encoding dicts with floats as keys (the keys are encoded as strings).

This refactors the number parsing routine (str -> int/float), with the
following results:

- Improved performance, up to 20% faster, dependent on message. This is
  most prominent for floats or long ints.
- Ability to reuse the same routine for converting strings to ints or
  floats (or int/float-like things). Previously we had a duplicate
  `str -> int` routine, and relied on cpython's float parser for the
  `str -> float` conversions. With this change we're able to delete a
  bunch of code.
- Expanded features. In particular, we can now support float-like
  strings as dict keys in JSON.
- Improved maintainability. The reorganized code should provide a better
  base to build new features off of.
We can now roundtrip dicts with float-like keys through JSON.
@jcrist jcrist merged commit ef7808b into main Aug 10, 2023
7 checks passed
@jcrist jcrist deleted the refactor-float-parsing branch August 10, 2023 20:14
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.

1 participant