Skip to content

Remove unnecessary CString allocation when loading functions#379

Merged
MaikKlein merged 1 commit intoash-rs:masterfrom
Traverse-Research:raw-string
Mar 1, 2021
Merged

Remove unnecessary CString allocation when loading functions#379
MaikKlein merged 1 commit intoash-rs:masterfrom
Traverse-Research:raw-string

Conversation

@MarijnS95
Copy link
Collaborator

@MarijnS95 MarijnS95 commented Feb 27, 2021

CString::new needs to perform an allocation to own the &'static str and append a NULL byte to it. We can instead perform this "allocation" in the generator and emit a byte-string literal with trailing NULL byte that can immediately be used by the function loader.


Note this is just a local test I wrote up. Not sure if it should go in but It might be beneficial towards all the embedded questions/issues where such allocations are out of the question.

Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

I, for one, am a fan of not having completely pointless mallocs even if it's off a hotpath, at least when the complexity impact is insignificant.

CString::new needs to perform an allocation to own the `&'static str`
and append a NULL byte to it. We can instead perform this "allocation"
in the generator and emit a byte-string literal with trailing NULL byte
that can immediately be used by the function loader.
@MarijnS95
Copy link
Collaborator Author

@Ralith Same thought here. It doesn't bring us much closer to no_std yet nor do I depend on using ash that way, but the sheer thought of saving a bunch of runtime allocations is satisfying.

@MaikKlein MaikKlein merged commit a053c6a into ash-rs:master Mar 1, 2021
@MarijnS95 MarijnS95 deleted the raw-string branch March 1, 2021 09:06
MarijnS95 added a commit that referenced this pull request Dec 27, 2021
Following the changes in a053c6a ("Remove unnecessary CString allocation
when loading functions (#379)") this addresses the remainder of string
allocations in manual extension loading code.
MarijnS95 added a commit that referenced this pull request Dec 27, 2021
Following the changes in a053c6a ("Remove unnecessary CString allocation
when loading functions (#379)") this addresses the remainder of string
allocations in manual extension loading code.
Ralith pushed a commit that referenced this pull request Dec 28, 2021
Following the changes in a053c6a ("Remove unnecessary CString allocation
when loading functions (#379)") this addresses the remainder of string
allocations in manual extension loading code.
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