Moataz-Aldawood commented on issue #18:
URL: https://github.com/apache/netbeans-vscode/issues/18#issuecomment-5233465152
Analysis: Auto-completion Latency in VS Code Extension (Issue #18)
1. The Red Herring: completion-auto-popup-delay
Initial investigations suggested that the 250ms delay experienced in the VS
Code extension was inherited from the NetBeans IDE editor setting
completion-auto-popup-delay (default: 250ms).
While manually overriding this setting to 0 fixes the latency in the
standard NetBeans IDE, applying the same CustomPreferences.xml in the VS Code
extension's user directory has no effect.
Why it doesn't work: In the standard NetBeans IDE,
completion-auto-popup-delay controls a UI Timer in the editor view. It delays
the initial request to the CompletionProvider.
However, in the VS Code extension architecture, the NetBeans Language Server
(NBLS) does not control the UI timer. VS Code's native frontend setting
(editor.quickSuggestionsDelay, default 10ms) controls the popup delay. When
this native 10ms timer fires, VS Code immediately sends a
textDocument/completion request over the Language Server Protocol (LSP). NBLS
completely ignores the completion-auto-popup-delay preference because it
operates headlessly and strictly responds to incoming LSP requests.
2. The True Cause: Synchronous IPC Configuration Fetching
If the UI timer is only 10ms, why does the extension take ~250ms+ to present
completions?
Analysis of the upstream NetBeans LSP server implementation reveals a
significant bottleneck in the hot path of the completion handler.
In
java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java,
the completion() method does the following:
```
List<String> configValues = List.of(
NETBEANS_JAVADOC_LOAD_TIMEOUT,
NETBEANS_COMPLETION_WARNING_TIME,
NETBEANS_CODE_COMPLETION_COMMIT_CHARS,
CLIENT_JAVA_COMPLETION_DISABLE_INSERT_METHOD_PARAMS
);
// Problematic Hot Path:
return
client.getClientConfigurationManager().getConfigurations(configValues,
uri).thenApply(c -> {
// ... computation of Java code completions ...
});
```
The Bottleneck: Every single time the user triggers code completion (which
happens continuously as they type), the NetBeans Language Server pauses
execution to make an asynchronous Remote Procedure Call
(workspace/configuration) back to the VS Code client to request four
configuration variables.
The server refuses to start calculating completions until the client
responds. This network round-trip across the inter-process stream introduces
significant, variable latency (often 100ms - 300ms depending on system load) to
every keystroke.
3. The Challenge & Proposed Architecture Fix
To resolve this latency, the upstream apache/netbeans Java codebase must be
modified.
Instead of dynamically fetching configuration values on the hot path of
textDocument/completion, the java.lsp.server should implement a Configuration
Cache.
Proposed Solution:
Fetch all necessary configuration values exactly once during server
initialization or the first request.
Store these values locally within the TextDocumentServiceImpl or a dedicated
Configuration Manager.
Hook into the LSP workspace/didChangeConfiguration notification to update
the cache asynchronously in the background whenever the user modifies their VS
Code settings.
Allow the completion() method to read instantly from this cache, unblocking
the thread and providing instantaneous completion generation.
WARNING
Because this fix requires architectural changes to the upstream netbeans
repository rather than the lightweight netbeans-vscode wrapper, it requires
coordination with the upstream maintainers to implement and test the
configuration caching correctly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists