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

[Perf] Reduce allocs when parsing Program #2516

Merged
merged 5 commits into from
Oct 26, 2024

Conversation

ljedrz
Copy link
Collaborator

@ljedrz ljedrz commented Jul 10, 2024

(transferred from ProvableHQ#5, and asking @d0cd for a review as suggested there)

Program parsing is something that has always been prominent in node heap profiles, and this PR targets its highest-level bits.

While parsing its components, we currently use a combination of the functions many1 and alt, which cause us to clone the parsed input at least once (more if it's not the expected component) for every component; this can be avoided by removing the use of alt in favor of a new intermediate function which is able to determine the type of the parsed component in advance and select the right parsing function without "making guesses". This is what the 1st commit does.

The 2nd commit avoids all the clones of program components that we currently perform presumably as a workaround introduced in order to be able to manage the notoriously tricky nom errors. With some refactoring (i.e. applying map_res only to potential errors), we are able to remove many allocations.

These changes reduce the number of allocations caused by the parsing of a Program in a 15-minute run of a --dev node by ~8% (an absolute decrease of over 54k allocs), making the process faster. The impact on the performance of the node as a whole depends on the number and size of the Programs it has to process.

@ljedrz ljedrz requested a review from d0cd July 10, 2024 08:31
Signed-off-by: ljedrz <[email protected]>
@ljedrz
Copy link
Collaborator Author

ljedrz commented Jul 10, 2024

CI run link

@ljedrz ljedrz marked this pull request as draft July 10, 2024 08:56
@ljedrz
Copy link
Collaborator Author

ljedrz commented Jul 10, 2024

Converting to draft for now, as the CI complains 🔍.

Edit: fixed.

@ljedrz ljedrz marked this pull request as ready for review July 10, 2024 09:48
@vicsn
Copy link
Contributor

vicsn commented Oct 22, 2024

Superseded by #2562 to resolve cargo fmt conflicts

@zosorock zosorock merged commit 58be36d into AleoNet:staging Oct 26, 2024
75 of 84 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.

5 participants