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

Performance improvements #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

garymardell
Copy link

I am using the protobuf library in a project of mine and after profiling I noticed that the majority of time serializing protobufs was occurring in these two places. I don't know if these are general enough changes that should be included in the library but thought I'd open the PR for discussion.

  • String#encode is the most expensive one by far. This accounted for a significant percentage of the profile time (~36%). In my use-case the strings are already encoded in UTF-8 and therefore this isn't required. This is also the common case in crystal as all strings by default are UTF-8 encoded.

  • After removing the string encoding in my profile I saw a large number of calls to Hash#fetch which stemmed from getting the wire type from ::Protobuf::WIRE_TYPES. We can move this lookup into the macro itself and have it happen at compile time rather than runtime.

@jgaskins
Copy link
Collaborator

I haven't gotten a chance to look at this yet, but performance has been on my list so I'm really glad to see it!

I'll take a look soon.

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.

2 participants