-
Notifications
You must be signed in to change notification settings - Fork 31
Improve the Sequel benchmark to avoid many singleton classes #207
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
Conversation
* These singleton classes are expensive to create and also cause a lot of uncached method lookups. * Both `Post.create` and `Post.where(id: i).first` create a new singleton class per call (through #clone of a dataset object which has a singleton class). * With this commit, no singleton classes are created during insertion and in `run_benchmark`. And therefore also no uncached method lookup.
57287de to
16edb13
Compare
|
The ActiveRecord benchmark does |
|
For the ActiveRecord benchmark, |
|
It seems to make sense to have more idiomatic/efficient use of sequel in the benchmark. @jeremyevans any input? |
|
|
|
FWIW, all extensions and plugins other than timestamps should be removed from the benchmark. The only one that has an effect is |
|
Thank you Jeremy. |
* And it will likely be fixed in Sequel to avoid creating a singleton class per call.
|
@jeremyevans @eregon My thinking for adding this benchmark is not find the most performant way to do a query in Sequel but to see if and how much YJIT can optimize code with the plugin strategy because it is a chain of method overrides using modules. Sequel has multiple ways to do a query and maybe the strategy should be to see how the fastest and slowest query methods perform in YJIT optimizations. If I were developing JIT, I would want different code strategies and see how JIT compiles and optimizes it. |
|
@hmistry I understand. I think what matters though is the benchmark is representative and benchmarks something meaningful, if it's benchmarking something nobody/very few use, then it's a not so useful benchmark, because it might lead to optimizing things that are irrelevant for actual performance in practice (and optimizing things take time). In this case, many singleton classes and uncached method lookup are pretty much pointless to benchmark on YJIT, this stuff is handled by the interpreter, YJIT or even any JIT can do little about it. Basically we found a performance issue in Sequel and that's getting fixed (jeremyevans/sequel#2007). Regarding the plugin strategy, AFAIK that is still being benchmarked with this PR (at least the various plugins are in |
Post.createandPost.where(id: i).firstcreate a new singleton class per call (through #clone of a dataset object which has a singleton class).run_benchmark. And therefore also no uncached method lookup.We discussed this in details on the CRuby Slack. @jeremyevans suggested using
Post[i]orPost.first(id: i)instead ofPost.where(id: i).first.I think what's important is to benchmark something representative of what users would use.
@jeremyevans Do you know if
Post[i]orPost.first(id: i)is frequently used by Sequel users? What's recommended in the documentation?Numbers on 3.2.1 YJIT:
Post.where(id: i).first(original): 130msPost.first(id: i): 79msPost[i]: 68msFor
DB[:posts].insert()vsPost.create(), I think it would be more representative to usePost.create(), but OTOH this is only part of the setup, not of the measured time, and it seems good to avoid too much side effects during the setup (Post.create()does cause one uncached method lookup (for aliteral_integercall site) forPost[i]).I think this is something to improve in Sequel,
Post.create()should be able to cache the dataset or avoid creating a new one, similar to whatDB[:posts].insert()does (jeremyevans/sequel#2007). So once that's fixed in Sequel we could usePost.create()again.Related: #205 #159