Avoid a second tree lookup in Workspace.getResourceInfo - #2883
Open
vogella wants to merge 1 commit into
Open
Conversation
getResourceInfo walked the element tree twice for every read access: once through ElementTree.includes and again through ElementTree.getElementData. The single-slot lookupCache that is meant to make the second walk free compares keys by identity and is shared by all threads, so under concurrent access (builders, indexers) it gets replaced between the two calls and the second walk runs for real. Add the internal ElementTree.getElementDataOrNull, which does one lookup and returns null when the element is absent, and use it for the non-mutable path. This removes one full tree walk plus one monitor acquisition from the hottest resource access path. Behavior is unchanged: a missing element and an element with null data both already resulted in null.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Workspace.getResourceInfois one of the hottest paths in the resources plug-in, and it walked the element tree twice for every read: once throughElementTree.includesand once more throughElementTree.getElementData. The single-slotlookupCachethat is supposed to make the second walk free compares keys by identity and is shared by all threads, so with builders and indexers hitting the sameElementTreeit gets replaced between the two calls and the second walk runs for real.This adds the internal
ElementTree.getElementDataOrNull, which performs one lookup and returnsnullwhen the element is absent, and uses it for the non-mutable case. That removes a full tree walk plus one monitor acquisition per call. Behavior is unchanged: an absent element and an element withnulldata both already producednull.org.eclipse.core.internal.watsonis internal, so there is no API impact.