perf(editor): index language modes instead of sorting on every lookup - #2881
Merged
Conversation
getModeForPath copied and sorted all registered modes per file, and the comparator recomputed specificity plus indexOf. File trees and icon plugins hit this for every entry. Rebuild a specificity index only when modes are added or removed, look up exact names / filename regexes / longest extension, and cache by basename. Matching still goes through supportsFile, with a scan fallback, so plugin register/unregister and later-wins ties stay the same. Keep resolving file-tree icons at render time so plugins that replace helpers.getIconForFile (for example Material Icons) still apply.
Contributor
|
This comment was marked as outdated.
This comment was marked as outdated.
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.
Summary
getModeForPathcopied and sorted every registered language mode on each call. Directory listing hits this via icon resolution for every file; the sidebar tree hits it again while rendering. Icon plugins that wraphelpers.getIconForFilepay the same cost.This rebuilds a lookup index only when
addMode/removeModerun (exact filenames, filename regexes in specificity order, longest extension suffix) and caches results by basename.File-tree icons are still resolved at render time. Caching the
sortDiricon class would skip plugins that replacehelpers.getIconForFile(Material Icons and similar), so that shortcut is intentionally not used here.A dedicated file/folder icon plugin API can replace those monkey-patches later. This PR does not add that API.
Compatibility
Public plugin APIs are unchanged:
acode.editorLanguages.*acode.aceModes.*ace.require("ace/ext/modelist")helpers.getIconForFile(still overridable)getModes()still returns registration order. Later plugin registrations still win on equal specificity. Register/unregister invalidates the index immediately.Parity-tested against the old sort-and-scan for built-in modes, Dockerfile case sensitivity, compound extensions, nginx/BUILD filename matchers, and plugin install/remove.
Measurements
4000 lookups (js/ts/json/py/md/css/unknown + Dockerfile/nginx/CMakeLists):
About 105× faster in unit tests. Calling
getIconForFiletwice per tree row is still cheap after this; the old sort was the hitch.Follow-up
Add a first-class file/folder icon plugin API so themes like Material Icons do not need to replace
helpers.getIconForFile.