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

Avoid eager initialization of Scope objects. #1680

Closed
whitingjr opened this issue Jan 18, 2023 · 1 comment · Fixed by #1681
Closed

Avoid eager initialization of Scope objects. #1680

whitingjr opened this issue Jan 18, 2023 · 1 comment · Fixed by #1681

Comments

@whitingjr
Copy link
Contributor

Scope objects are being initialized without necessarily being used.
To avoid allocation and gc pressure this issue proposes lazy initialization.

@whitingjr
Copy link
Contributor Author

A JMH benchmark has been created in a demo project on this branch. To run the benchmark:
mvn install the jaxb-ri project. Then mvn package the benchmark project. Then start the benchmark using the generated jar file. java -jar target/benchmarks.jar

Lazy initialization and retrieval of Scope objects is shown to be more efficient. Shown using these results (lower is better).

Benchmark                           Mode  Cnt  Score   Error  Units
MyBenchmark.testGetScopeEager         ss   50  0.622 ± 0.066   s/op
MyBenchmark.testGetScopeLazy          ss   50  0.450 ± 0.064   s/op
MyBenchmark.testInstantiationEager    ss   50  0.654 ± 0.176   s/op
MyBenchmark.testInstantiationLazy     ss   50  0.402 ± 0.041   s/op

The garbage collector pressure also is improved. Shown with the pauses profiler using JMH (lower is better)

Benchmark                                           Mode  Cnt      Score   Error  Units
MyBenchmark.testGetScopeEager                         ss   50      0.672 ± 0.095   s/op
MyBenchmark.testGetScopeEager:·pauses                 ss  252  17033.651             ms
MyBenchmark.testGetScopeEager:·pauses.avg             ss          67.594             ms
MyBenchmark.testGetScopeEager:·pauses.count           ss         252.000              #
MyBenchmark.testGetScopeLazy                          ss   50      0.446 ± 0.117   s/op
MyBenchmark.testGetScopeLazy:·pauses                  ss  131  11416.635             ms
MyBenchmark.testGetScopeLazy:·pauses.avg              ss          87.150             ms
MyBenchmark.testGetScopeLazy:·pauses.count            ss         131.000              #
MyBenchmark.testInstantiationEager                    ss   50      0.678 ± 0.113   s/op
MyBenchmark.testInstantiationEager:·pauses            ss  288  17113.085             ms
MyBenchmark.testInstantiationEager:·pauses.avg        ss          59.420             ms
MyBenchmark.testInstantiationEager:·pauses.count      ss         288.000              #
MyBenchmark.testInstantiationLazy                     ss   50      0.412 ± 0.036   s/op
MyBenchmark.testInstantiationLazy:·pauses             ss  131  11296.743             ms
MyBenchmark.testInstantiationLazy:·pauses.avg         ss          86.235             ms
MyBenchmark.testInstantiationLazy:·pauses.count       ss         131.000              #

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant