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

Optimize CacheKey handling in SpringIterableConfigurationPropertySource #16717

Conversation

dreis2211
Copy link
Contributor

@dreis2211 dreis2211 commented May 4, 2019

Hi,

as described in #16401 there is an optimization opportunity in SpringIterableConfigurationPropertySource when checking for CacheKey equality. Currently, for large Sets this takes a considerable amount of time as the two Sets are usually equal, but not the same instance. This is due to the fact that the internal key inside CacheKey is copied in order to fix #13344 and can thus not benefit from a == comparison.

The idea of this PR is to introduce a flag that effectively disables the copying of the internal key under certain circumstances. Imho, this could be done for OriginTrackedMapPropertySource instances which is used to load either .yaml or .properties files, which usually shouldn't be a subject of change (and even if require a refresh of some sort). I still implemented an additional check for the size of the internal key in a best effort to track key additions at least for OriginTrackedMapPropertySources, too.

With the applied changes, I see major improvements compared to a M2 baseline.

Baseline New
12.757 7.947
11.742 8.254
12.453 7.790
12.819 7.513
12.588 8.021
12.616 8.038
12.541 7.495
13.555 7.864
12.494 8.040
12.009 7.726
Mean 12.557 7.869
Range 1.813 0.759

Let me know what you think.

Cheers,
Christoph

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 4, 2019
@dreis2211
Copy link
Contributor Author

As an addendum. This brings us pretty close to the performance of 1.5 for such big files.

Baseline New
8.741 7.931
7.650 7.873
7.475 7.834
8.305 7.890
7.574 8.064
7.719 8.019
7.779 7.722
7.700 7.417
7.903 7.750
7.293 8.103
Mean 7.814 7.860
Range 1.448 0.686

@dreis2211
Copy link
Contributor Author

Test failure seems unrelated

@philwebb philwebb added theme: performance Issues related to general performance type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 14, 2019
@philwebb philwebb added this to the 2.2.x milestone May 14, 2019
@philwebb
Copy link
Member

Thanks @dreis2211, sorry about the delay getting to these. I hope to review soon.

@dreis2211
Copy link
Contributor Author

dreis2211 commented May 15, 2019

Don't worry. There's release preparation, the new annotations API and it's conference season etc.. Whenever you're ready :)

@philwebb philwebb self-assigned this Jun 4, 2019
@philwebb philwebb modified the milestones: 2.2.x, 2.2.0.M4 Jun 4, 2019
@philwebb
Copy link
Member

philwebb commented Jun 4, 2019

This is great!!! I've updated things a little in this commit so that sources actually need to declare themselves as immutable. We can then use a shared cache key that always matches. This should save us from even creating the CacheKey. Fantastic work. Thanks once again @dreis2211.

philwebb pushed a commit that referenced this pull request Jun 4, 2019
Update `SpringIterableConfigurationPropertySource` so that cache keys
do not need to be checked if property sources are immutable.

See gh-16717
philwebb added a commit that referenced this pull request Jun 4, 2019
Make immutable properties more explicit and trust that they
truly won't change.

See gh-16717
@philwebb philwebb closed this in 05ad955 Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: performance Issues related to general performance type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants