Nanox so fix#4
Merged
Merged
Conversation
0cda5fb to
ab9d858
Compare
89e9fb0
into
feature/refactor-too-big
34 of 35 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The reason why tests in
feature/refactor-too-bigcrash is stack overflow, which happens because some large objects are passed/returned/moved by value. I fixed the crash by boxing them.I documented my findings about the apps stack usage in
docs/memory_usage.md(in particular, how to measure it), but in short: passing, returning or even moving around large objects eats up large amounts of stack space and currently we only have less than 12KB of it on nanox.Details:
sizeofs of some objects infeature/refactor-too-big:TxParsingInputsContext: 688
SignTxReq: 264
mlcp::SighashInputCommitment: 208
TxInputReq: 264
TxOutputReq: 192
Response: 100
NbglStreamingReview: 48
I boxed those with sizes around 200 bytes or more.
Original stack frame sizes (sorted by frame size, bigger first):
A sidenote: one interesting thing is that if I marked
fn decode_allas#[inline(never)], then I could see:I.e. more than 1 KB of stack usage above may be attributed to the inlined
decode_all(not that we can do much about it, just an observation).After boxing each variant of
TxParsingContextI got:Then I boxed by-value self in
XxxContextmethods:Then I boxed the contents of
SignTxReqand made the correspondenthandle_functions acceptBox:After removing "chain-error" from parity-scale-codec's features, the compiler decided to inline
handle_commandand I got:But note that the new total size of
sample_mainandhandle_sign_txstack frames is less than the old total size ofsample_main+handle_command+handle_sign_tx.For clarity I also recompiled it with
handle_commandmarked with#[inline(never)]:So removing "chain-error" reduced
handle_command's stack usage by about 100 bytes. Not a big deal, but on the other hand we don't benefit from "chain-error" in any way, because we never examine decoding errors and don't even print them.For comparison, frame sizes in
feature/mintlayer-appare:P.S.
--golden_run, because the snapshots are outdated.ledger_secure_sdk_sysversion to1.16.1(same as infeature/mintlayer-app) - this is just to make results in the two branches comparable.