-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add replace_methods
argument to BatchLoader#batch
#45
Add replace_methods
argument to BatchLoader#batch
#45
Conversation
@exAspArk would you mind taking a look, please? |
da28873
to
ffc1abe
Compare
Thanks @exAspArk, I made a few changes and added questions for the others. |
The existing `cache` argument does two things: 1. `#__sync` uses it to set a `@synced` instance variable, which tells later calls to `#__sync` not to reload the value when another method is called on it. 2. `#__sync!` uses it to replace methods on the proxied object with their 'real' equivalents. This delegates responsibility for item 2 to the new `replace_methods` argument instead. In testing (and in the benchmarks added here) we've seen that `#__replace_with!` can actually take up an appreciable amount of time, and removing it is faster, even though each individual method call is slower. The default for this new argument is to `true`. It's very likely that `cache: false, replace_methods: true` will give surprising results.
ffc1abe
to
e2f4b67
Compare
@smcgivern thanks a lot! 🙌 |
I released your changes in batch-loader/lib/batch_loader.rb Line 29 in 77d3264
|
Thanks @exAspArk! ❤️ I like this explanation:
I'll look at getting this into GitLab this week. |
We've seen a significant performance penalty when using `BatchLoader#__replace_with!`. This defines methods on the batch loader that proxy to the 'real' object using send. The alternative is `method_missing`, which is slower. However, we've noticed that `method_missing` can be faster if: 1. The objects being loaded have a large interface. 2. We don't call too many methods on the loaded object. Avatar uploads meet both criteria above, so let's use the newly-released feature in exAspArk/batch-loader#45. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/60903
We've seen a significant performance penalty when using `BatchLoader#__replace_with!`. This defines methods on the batch loader that proxy to the 'real' object using send. The alternative is `method_missing`, which is slower. However, we've noticed that `method_missing` can be faster if: 1. The objects being loaded have a large interface. 2. We don't call too many methods on the loaded object. Avatar uploads meet both criteria above, so let's use the newly-released feature in exAspArk/batch-loader#45. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/60903
In production, we've seen the rendering times of the merge request widget increase as a result of loading commit data. BatchLoader attempts to call replace_methods on the lazy object, but this has a significant performance penalty for modules that have many methods. Disabling this mode (exAspArk/batch-loader#45) appears to cut load times by about 50% for MergeRequestsController#show. Relates to https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/6941
In production, we've seen the rendering times of the merge request widget increase as a result of loading commit data. BatchLoader attempts to call replace_methods on the lazy object, but this has a significant performance penalty for modules that have many methods. Disabling this mode (exAspArk/batch-loader#45) appears to cut load times by about 50% for MergeRequestsController#show. Relates to https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/6941
We've seen a significant performance penalty when using `BatchLoader#__replace_with!`. This defines methods on the batch loader that proxy to the 'real' object using send. The alternative is `method_missing`, which is slower. However, we've noticed that `method_missing` can be faster if: 1. The objects being loaded have a large interface. 2. We don't call too many methods on the loaded object. In production, we've seen the rendering times of the merge request widget increase as a result of loading commit data. BatchLoader attempts to call replace_methods on the lazy object, but this has a significant performance penalty. Disabling this mode (exAspArk/batch-loader#45) appears to cut load times by about 50% for MergeRequestsController#show. Relates to https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/6941
We've seen a significant performance penalty when using `BatchLoader#__replace_with!`. This defines methods on the batch loader that proxy to the 'real' object using send. The alternative is `method_missing`, which is slower. However, we've noticed that `method_missing` can be faster if: 1. The objects being loaded have a large interface. 2. We don't call too many methods on the loaded object. In production, we've seen the rendering times of the merge request widget increase as a result of loading commit data. BatchLoader attempts to call replace_methods on the lazy object, but this has a significant performance penalty. Disabling this mode (exAspArk/batch-loader#45) appears to cut load times by about 50% for MergeRequestsController#show. Relates to https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/6941
The existing
cache
argument does two things:#__sync
uses it to set a@synced
instance variable, which tellslater calls to
#__sync
not to reload the value when another method iscalled on it.
#__sync!
uses it to replace methods on the proxied object withtheir 'real' equivalents.
This delegates responsibility for item 2 to the new
replace_methods
argument instead. In testing (and in the benchmarks added here) we've
seen that
#__replace_with!
can actually take up an appreciable amountof time, and removing it is faster, even though each individual method
call is slower.
The default for this new argument is to match
cache
. Only if it'sexplicitly set to
true
orfalse
will it not do that, and if it isset to
true
andcache
isfalse
we raise an error, because thatdoesn't make sense.
Closes #43.