various: reduce allocations where available #22
Merged
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.
Small PR that focuses on performance improvements and code simplification for string formatting throughout the codebase. The main changes involve replacing
format!macros and similar formatting methods with manual string construction using pre-allocated buffers and thewrite!macro, which reduces heap allocations and improves runtime efficiency.Reduces heap allocations by a whopping 61% across all system information gathering functions and, consequently, achieves a near 45x speednup for the main I/O bottleneck through optimized buffer management. This is achieved mostly replacing
format!macros with pre-allocated string building to minimize memory overhead.The allocations, according to Hotpath, have gone done from 54 total allocations to 21! That's 33 fewer allocations or a 61% reducation as I've claimed above. The main change is to
release::get_os_pretty_namewhich went from 16 to 2 allocations, which is a 87.5% reduction.Good changes overall, hope nothing changes. I was going to add some in-line assembly but we're in a good spot for now.
Signed-off-by: NotAShelf [email protected]
Change-Id: I6a2158a305d5f249b52c8b21dc5aaca86a6a6964