Created by: Fryguy
Fixes #12648 (closed)
Requiring all models up front can be very expensive in both time and memory if there are many models. In an example client with 6000 models, this would consume nearly 400MB of memory and take about 7 seconds to load. This is mostly unnecessary as most users of the client library will only actually use a small percentage of the library.
The changes in this commit use Ruby's autoload capability to defer the loading until the constant is actually used. In that same example client with 6000 models, when initially requiring the library, the memory usage dropped to ~20MB and loaded in 0.3 seconds. As the constants are loaded on-demand, the memory would increase towards that 400MB ceiling, but if only a few constants are actually used, then memory will never actually hit that ceiling.
An additional side effect of using Ruby's autoload is that the order of declaring the constants is not important, as Ruby will naturally load them in the correct order when they are needed. Thus, this commit obviates PR #9103 and fixes #4690 (closed).
@cliffano @zlx @autopp Please review. I filed this against master, but if you think it should go elsewhere, please let me know.
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
(6.0.1) (patch release),6.1.x
(breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks) -
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.