-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Pico] Improved performance #2725
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2725 +/- ##
=========================================
Coverage 84.98% 84.99%
- Complexity 2723 2724 +1
=========================================
Files 330 330
Lines 9556 9555 -1
Branches 916 915 -1
=========================================
Hits 8121 8121
Misses 1111 1111
+ Partials 324 323 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
cucumber-picocontainer/src/main/java/io/cucumber/picocontainer/PicoFactory.java
Show resolved
Hide resolved
68b6c54
to
e5897b2
Compare
cucumber-picocontainer/src/main/java/io/cucumber/picocontainer/PicoFactory.java
Show resolved
Hide resolved
@jkronegg I can't find flaw this with MR. But it bothers me that we can simply skip invoking the life cycle methods on pico container and still see the same effect. Could you provide a brief rationale why this works? Or if brief takes up too much time, a slightly longer explanation is fine too. |
I tried to use the As the picocontainer has been created "withCaching", my second trial was to look for a cache eviction method, but I could not find one. My third approach (in this MR) is to remove the instances held by the Then I ran the I must admit : there is a part of empirical/brute force in the approach, I'm no picocontainer expert, and I was also surprised that it worked without much effort (it's only about 1 hour of work)😅. |
Mmh. I suppose because we are not using nested containers and only components, we can get away with skipping the lifecycle for the containers. But I'm going to let this MR sit until I have some more time to look into Pico Containers features. Pico Container is one of the more common DI containers for Cucumber and has been around for a long time. There is a fair chance it is subject to Hyrum's Law. |
Okay. I think this is mostly fine because
One case where Hyrum might come and bite us is the order in which the components are shut down.Pico Container does this in a specific order: private void stopAdapters() {
for (int i = getOrderedComponentAdapters().size() - 1; 0 <= i; i--) {
ComponentAdapter<?> adapter = getOrderedComponentAdapters().get(i);
if (adapter instanceof ComponentLifecycle) {
ComponentLifecycle<?> componentLifecycle = (ComponentLifecycle<?>)adapter;
if (componentLifecycle.componentHasLifecycle() && componentLifecycle.isStarted()) {
componentLifecycle.stop(DefaultPicoContainer.this);
}
}
}
} This order appears to be the reverse order in which components are defined. But because we define from a unordered collection this should be fine there too. cucumber-jvm/cucumber-picocontainer/src/main/java/io/cucumber/picocontainer/PicoFactory.java Lines 16 to 34 in b182cf8
|
Corrected the pico-container lifecycle: the start, stop and dispose methods are now called for every test scenarios. The code is the same as before #2725 (so it's safer in terms of lifecycle), except that the pico container is recycled in the `start()` method when it already exists. When a second call to `start()` is done (e.g. for the 2nd scenario), the container component instances are all in disposed state and the container lifecycle is in disposed state. The recycling operation consists in removing all container component instances (i.e. flushing the cache) and resetting the container lifecycle. Co-authored-by: Julien Kronegg <julien [at] kronegg.ch>
🤔 What's changed?
Improved picontainer performance by reusing the library initialization (basically: clear the cache on
stop()
).⚡️ What's your motivation?
Solves #2724 .
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
The issue cannot be resolved in the picocontainer library itself (picocontainer/picocontainer#11) because the library seems not maintained anymore.
📋 Checklist: