Draft
Conversation
On master, each events has an impl for TryFrom<&[u8]>. protocol::Event uses this impl to parse the event and then wrap it in the Event enum. This means that the result from the TryFrom implementation has to be copied into the Event enum and the generated code actually contains such a copy. Actually, it contains many such copy sequences, one per event. This commit changes the structure a bit. Each event gets a function ugly_hack(&[u8]) -> Result<Event, ParseError>. Thus, protocol::Event only has to figure out which event this is and then call that event's ugly_hack(). This function then immediately constructs an instance of Event, thus avoiding the copy-bytes-around in the caller. This commit changes the size of the stripped xclock_utc example in a release build from 503 KiB to 495 KiB. This is a reduction in binary size by about 2.5 %. The assembler code for the full library goes from 159662 to 158847 lines (0.5% less), but the object file (.o) keeps its size / does not change. You might notice from the function name "ugly_hack" that I am not really happy with this implementation. Instead, I wanted to check if the general approach has merits. Apparently it does.
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.
On master, each events has an impl for TryFrom<&[u8]>. protocol::Event
uses this impl to parse the event and then wrap it in the Event enum.
This means that the result from the TryFrom implementation has to be
copied into the Event enum and the generated code actually contains such
a copy. Actually, it contains many such copy sequences, one per event.
This commit changes the structure a bit. Each event gets a function
ugly_hack(&[u8]) -> Result<Event, ParseError>. Thus, protocol::Event
only has to figure out which event this is and then call that event's
ugly_hack(). This function then immediately constructs an instance of
Event, thus avoiding the copy-bytes-around in the caller.
This commit changes the size of the stripped xclock_utc example in a
release build from 503 KiB to 495 KiB. This is a reduction in binary
size by about 2.5 %.
The assembler code for the full library goes from 159662 to 158847 lines
(0.5% less), but the object file (.o) keeps its size / does not change.
You might notice from the function name "ugly_hack" that I am not really
happy with this implementation. Instead, I wanted to check if the
general approach has merits. Apparently it does.
This is related to #488.