Skip to content

Use memoized suppliers to lazy load resources#2658

Merged
ctubbsii merged 1 commit intoapache:mainfrom
ctubbsii:memoize-improvements
Apr 28, 2022
Merged

Use memoized suppliers to lazy load resources#2658
ctubbsii merged 1 commit intoapache:mainfrom
ctubbsii:memoize-improvements

Conversation

@ctubbsii
Copy link
Copy Markdown
Member

  • Remove the need to synchronize on reads for lazily initialized
    singleton resources, particularly in the configuration and context
    utilities, using Suppliers.memoize
  • Apply to DefaultConfiguration.getInstance() to avoid unnecessary
    object creation whenever that is called
  • Make all ServerContext fields final, and use memoize to lazily load
    anything that was previously checking if it was set in a synchronized
    getter method
  • Use computeIfAbsent in ServerConfigurationFactory, and make its caches
    of configuration objects non-static, so they only live as long as the
    ServerContext that created it lives; this, along with using
    ConcurrentHashMaps, dramatically simplifies this code
  • Reduce ServerContext reliance on ServerConfigurationFactory when it
    already has the information (notably, it has the instance of
    SiteConfiguration it used to construct the ServerConfigurationFactory)
  • Add a builder option for SiteConfiguration.empty() for use with tests
  • Update related tests, and make ServerContextTest.testCanRun more
    robust

* Remove the need to synchronize on reads for lazily initialized
  singleton resources, particularly in the configuration and context
  utilities, using Suppliers.memoize
* Apply to DefaultConfiguration.getInstance() to avoid unnecessary
  object creation whenever that is called
* Make all ServerContext fields final, and use memoize to lazily load
  anything that was previously checking if it was set in a synchronized
  getter method
* Use computeIfAbsent in ServerConfigurationFactory, and make its caches
  of configuration objects non-static, so they only live as long as the
  ServerContext that created it lives; this, along with using
  ConcurrentHashMaps, dramatically simplifies this code
* Reduce ServerContext reliance on ServerConfigurationFactory when it
  already has the information (notably, it has the instance of
  SiteConfiguration it used to construct the ServerConfigurationFactory)
* Add a builder option for SiteConfiguration.empty() for use with tests
* Update related tests, and make ServerContextTest.testCanRun more
  robust
@ctubbsii ctubbsii self-assigned this Apr 28, 2022
@milleruntime
Copy link
Copy Markdown
Contributor

Were these changes pulled from the ZK single node prop store refactor?

@EdColeman
Copy link
Copy Markdown
Contributor

Yes - the goal is to submit changes that are adjacent to the single node changes and have them submitted separately to reduce the number of absolute changes in the single node PR. It also contains changes that @ctubbsii identified during his review that were not originally in the single node PR, but are general code improvements and were in areas touched by the single node PR

If these changes are merged, the the single prop node PR can be overlaid on top of them with work that is being done as part of his review.

@ctubbsii ctubbsii merged commit ba244f6 into apache:main Apr 28, 2022
@ctubbsii ctubbsii deleted the memoize-improvements branch April 28, 2022 17:47
@ctubbsii ctubbsii added this to the 2.1.0 milestone Jul 12, 2024
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 this pull request may close these issues.

3 participants