Repository navigation
Conversation
Painting rebuilt the whole completion directory from the command and tool registries on every idle repaint, consuming over 10% CPU while idle. Cache the catalog in the UI completion closure and invalidate it through a monotonic extension registry generation advanced at every catalog input write point.
Contributor
Author
|
This PR only fixed the issue of CPU utilization during idle. |
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.
Idle repaints no longer rebuild the completion catalog.
application-operation-connect-uiinstalls a cached completion closure on the terminal UI.The closure stores three values:
entries,generation,registry.terminal-ui-completion-functioncompares the stored values with the current values on each paint.A match returns
entries.A mismatch rebuilds the catalog through
application-operation-completion-entries.A held lock leaves the catalog one paint behind.
The closure returns
entrieswhen it cannot take*extension-registry-transaction-lock*.The next paint sees the change.
Waiting would deadlock with a writer that needs the UI lock.
One counter covers every catalog input.
extension-registry--advance-generationincrements*extension-registry-generation*.application-command--publish-registrationscalls it for every command write.tool-registry-registercalls it for tool additions.tool-registry-delete-ifcalls it for tool removals.tool-registry-restrictcallstool-registry-delete-if. It needs no separate increment.Reads leave the counter unchanged.
application-command-listopens the registry transaction on the read path.An increment inside that transaction would invalidate the cache on every paint.
Registry writes reach the cached closure through one call chain.
A CPU profile identified the hotspot.
Sampling an idle image attributed over 10% CPU to
application-operation-completion-entries.The catalog has three inputs: the command registry, the tool registry, static help sections.
Those inputs change only inside registry write transactions.