Skip to content

Support exponent numbers an efficiency improvements for Hex int parsing#102

Merged
EnriqueL8 merged 1 commit into
mainfrom
hexinteger-fastpath
Jun 23, 2026
Merged

Support exponent numbers an efficiency improvements for Hex int parsing#102
EnriqueL8 merged 1 commit into
mainfrom
hexinteger-fastpath

Conversation

@peterbroadhurst

Copy link
Copy Markdown
Contributor

Parsing HexInteger is hot code in JSON/RPC interactions, and very often there are very small numbers - particularly zero.

Flame graph analysis shows we spend quite a lot of compute on allocating and parsing integers for these cases, so it's worth a low level optimization for the trivial cases.

Also I observed we were using big.Float parsing which doesn't handle exponent notation like 1e10, which is valid in JSON.

…sing

Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
@peterbroadhurst peterbroadhurst requested a review from a team June 23, 2026 01:13
Base automatically changed from rpc-generics to main June 23, 2026 09:03

@EnriqueL8 EnriqueL8 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice optimization

*h = HexInteger{} // zero big.Int has nil abs — no allocation
return nil
case c >= '1' && c <= '9':
*h = HexInteger(*big.NewInt(int64(c - '0')))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah this is cleaver stuff the c - '0' to convert a byte to numeric

@EnriqueL8 EnriqueL8 merged commit 1ac3f74 into main Jun 23, 2026
2 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.

3 participants