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 of deny_* methods by not raising in prod environments #1632

Merged
merged 7 commits into from
Nov 23, 2022

Conversation

camertron
Copy link
Contributor

Description

It was brought to our attention that dotcom spends a lot of time in the deny_single_argument method. This PR is an attempt to make it faster by skipping the check in production. We follow a similar approach in other parts of the codebase to avoid raising errors in production, which we should be doing for the various deny_* methods as well. So, we get more consistent behavior and more performance 🤗 Speaking of performance, here's the speedup:

$> RAILS_ENV=production bx rails r bench.rb 
Warming up --------------------------------------
             control    14.772k i/100ms
Calculating -------------------------------------
             control    149.042k (± 5.9%) i/s -    753.372k in   5.073306s

Pausing here -- run Ruby again to measure the next benchmark...

$> RAILS_ENV=production bx rails r bench.rb 
Warming up --------------------------------------
           optimized    19.347k i/100ms
Calculating -------------------------------------
           optimized    198.415k (± 3.4%) i/s -      1.006M in   5.076516s

Comparison:
           optimized:   198415.1 i/s
             control:   149042.0 i/s - 1.33x  (± 0.00) slower

I'm seeing an improvement in the 30-35% range.

Integration

Does this change require any updates to code in production?

No.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews

@changeset-bot
Copy link

changeset-bot bot commented Nov 22, 2022

🦋 Changeset detected

Latest commit: b70528c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the ruby Pull requests that update Ruby code label Nov 22, 2022
@camertron camertron temporarily deployed to review-pr-1632 November 22, 2022 22:35 Inactive
@camertron camertron temporarily deployed to github-pages November 22, 2022 22:39 Inactive
@camertron camertron marked this pull request as ready for review November 22, 2022 22:43
@camertron camertron requested review from a team and jonrohan November 22, 2022 22:43
Copy link
Member

@jonrohan jonrohan left a comment

Choose a reason for hiding this comment

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

Not blocking, but I was wondering if we could solidify this performance gain somehow in a test in test/performance/

@camertron
Copy link
Contributor Author

@jonrohan that's a great idea. Maybe we could add a test that ensures the prod version is faster than the non-prod version. Let me see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants