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] Eliminate initial soft-stack allocation #8

Open
DavidBuchanan314 opened this issue Oct 31, 2024 · 0 comments
Open

[perf] Eliminate initial soft-stack allocation #8

DavidBuchanan314 opened this issue Oct 31, 2024 · 0 comments

Comments

@DavidBuchanan314
Copy link
Owner

DavidBuchanan314 commented Oct 31, 2024

per benchmarks https://github.com/DavidBuchanan314/dag-cbor-benchmark we're significantly slower than libipld for very short messages.

This is likely in large part due to the sizeable initial stack allocations we do

size_t stack_len = 16;
DCToken *parse_stack = malloc(stack_len * sizeof(*parse_stack));

dag-cbrrr/src/cbrrr/_cbrrr.c

Lines 1042 to 1043 in ad56c83

size_t stack_len = 16;
EncoderStackFrame *encoder_stack = malloc(stack_len * sizeof(*encoder_stack));

We should use a small stack-allocated buffer for the initial stack, then move to heap when we run out of that (which implies a buffer copy, but probably worth it overall? - or maybe we could avoid the copy by treating the heap allocation as "overflow" room)

Ditto for the buffer we decode into? We'll always need at least one allocation, though

buf.buf = malloc(buf.capacity);

@DavidBuchanan314 DavidBuchanan314 changed the title Eliminate initial stack allocation Eliminate initial soft-stack allocation Nov 1, 2024
@DavidBuchanan314 DavidBuchanan314 changed the title Eliminate initial soft-stack allocation [perf] Eliminate initial soft-stack allocation Nov 1, 2024
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

No branches or pull requests

1 participant