-
Notifications
You must be signed in to change notification settings - Fork 18
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
[WIP] Fix performance issue when decorator files are loaded multiple times #29
[WIP] Fix performance issue when decorator files are loaded multiple times #29
Conversation
- To reduce the number of variables involved
@apotonick may be interested in taking a look at the patches: https://github.com/luma-institute/roar-jsonapi-test/tree/master/patches |
This is definitely a problem: assert_performance_constant do |n|
n.times do |i|
# simulates Rails auto-reloading
load File.join($SAMPLES_PATH, 'simple_single_resource_object_decorator.rb')
end
SimpleSingleResourceObjectDecorator.new(Article.new(1, 'My Article')).to_json
end The representer is not designed to be loaded multiple times - this will of course lead to wrong behavior such as filling up a declarative variable |
Hey friends, I was playing a bit with this and came to the following conclusions.
|
And: |
Update: The bug can also be provoked without the Damn, someone pour me a scotch. |
Ok, the problem is that reloading in Ruby simply doesn't work. I could replicate the problem without any Roar or Representable, just any inheritance/ Personally, I'm unsure about how to tackle this. I am not willing to design my libraries to work with Rails autoloading and/or poor pseudo reloading mechanism that never really work. |
@apotonick thanks for taking the time to dig into this, this doesn't seems to be something easy to address. Hope we find way around this problem. |
I am pretty sure this should work as expected when sticking to the Rails file naming convention, which works with TRB, too. Any results on this? |
We took this code out of our critical path for our product work for now. I did change code in an internal PR to match the Rails file naming conventions and it seemed to help. Waiting on a code review to confirm with some other folks. |
@apotonick just tested what @patcoll did and it works in our project. :) |
It's worth mentioning here that the fix we ended up using involved matching the class names to a standard Ruby file naming convention in a I believe the following factors contributed to our successful fix:
With that configured, an attempt to use the |
@myabc ☝️ Sounds good!?! |
It's also worth mentioning that we tested without app/concepts folder being added explicitly and it worked the same. Rails 5.0.1 |
@apotonick remind me of the question! |
NOTE: This is a work-in-progress.
Fixes #28
Here is a proof-of-concept here that shows the slowdown:
https://github.com/luma-institute/roar-jsonapi-test
In our case, we use
trailblazer
androar-jsonapi
within Rails, and the performance slowdown showed up in our development environment. We were able to reproduce the problem without Rails being involved, both in the linked repo and with a minimal benchmark test case in this PR.Failing test written first. Goal is to come up with a minimal fix to be applied to this repo to make the test pass and thus remove the slowdown.