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

Improve performance for serialization of entities #76

Merged
merged 8 commits into from
Jun 11, 2014

Conversation

justfalter
Copy link
Contributor

Hi there,

I spent a little bit of time profiling grape-entity using ruby-prof, and found a couple of ways to improve performance during the serialization process. This changeset sees Grape::Entity serializing ~2.5 times faster, by my benchmark.

Before:

$ bundle exec ruby bench/serializing.rb
       user     system      total        real
serializing  1.800000   0.000000   1.800000 (  1.800179)

After:

$ bundle exec ruby bench/serializing.rb
       user     system      total        real
serializing  0.750000   0.000000   0.750000 (  0.751563)

@dblock
Copy link
Member

dblock commented Jun 11, 2014

This is great! The build is still failing, if you could please take a look. Also please do update CHANGELOG.

@justfalter
Copy link
Contributor Author

Hi @dblock, it looks like the issue is that rspec 3 was released. I just sent another pull request to fix it (#77)... If that goes through, I'll be able to merge the changes into my branch so that it doesn't look like I'm awful at writing code.

- be_true/ be_false are no longer equivalent to "== true"/"==
  false" within rspec 3.0.
- Prevent constant rebuilding of Entity's @exposures class instance variable,
  improving serialization performance by 25%.
- Was being rebuilt over and over again. Performance improvement of
  about 25%.
- Buys another ~10% of performance gain
- Avoid using the to_s, split, last, to_sym chain. Improves performance
  another ~10%.
@justfalter
Copy link
Contributor Author

I've updated the changelog and rebased against #77 .

dblock added a commit that referenced this pull request Jun 11, 2014
Improve performance for serialization of entities
@dblock dblock merged commit 5daa2c9 into ruby-grape:master Jun 11, 2014
@justfalter
Copy link
Contributor Author

Yay! Glad I could help!

@justfalter justfalter deleted the improve_performance branch June 11, 2014 22:05
@justfalter
Copy link
Contributor Author

Out of curiosity, when would the next release occur? I'm eager to leverage this code without having to do goofy Gemfile tricks. Thanks again!

@dblock
Copy link
Member

dblock commented Jun 12, 2014

I plan to make a release soon, maybe next week? I usually integrate it into our very large API project first, that just takes me a while to wait on builds/tests to finish...

@dblock
Copy link
Member

dblock commented Jun 12, 2014

Oh wait, this is grape-entity, not Grape. I can cut a small release now.

@dblock
Copy link
Member

dblock commented Jun 12, 2014

Et voila, 0.4.4 is out. Performance is a good argument :)

@etehtsea
Copy link
Contributor

👍

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