-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decrease input-lag for large queries (#158)
* proof of concept * merge main * works again * fix overuse of main channel * mellan * tests work * fix worker thread for node as well * self review * self review * self review * fix build * tests * fix e2e test * merge semantic analsysis and syntax errors again * review comments * self review * fix tests * worker pool-ish for vscode * smarter 'pool' mgmt * kindaworks * works * cleanup new parser adapter * restore pkg json * workerpool * worker pool for client as well * cleanup workers * fix errors * fix tests * fix todos * fix build * test-are-green * works for vite * fixlint * self review * re-add proper build * fix input lag even when parse is fast * add changeset * fix e2e test * pr comments
- Loading branch information
1 parent
7768efd
commit 1e210cb
Showing
27 changed files
with
627 additions
and
239 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@neo4j-cypher/react-codemirror-playground': patch | ||
'@neo4j-cypher/language-support': patch | ||
'@neo4j-cypher/react-codemirror': patch | ||
'neo4j-cypher-vscode-extension': patch | ||
'@neo4j-cypher/language-server': patch | ||
--- | ||
|
||
Moves semantic analysis to a separate worker file |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { validateSemantics } from '@neo4j-cypher/language-support'; | ||
import workerpool from 'workerpool'; | ||
|
||
workerpool.worker({ validateSemantics }); | ||
|
||
type LinterArgs = Parameters<typeof validateSemantics>; | ||
|
||
export type LinterTask = workerpool.Promise< | ||
ReturnType<typeof validateSemantics> | ||
>; | ||
|
||
export type LintWorker = { | ||
validateSemantics: (...args: LinterArgs) => LinterTask; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { | ||
findEndPosition, | ||
parserWrapper, | ||
validateSyntax, | ||
} from '@neo4j-cypher/language-support'; | ||
import debounce from 'lodash.debounce'; | ||
import { join } from 'path'; | ||
import { Diagnostic, TextDocumentChangeEvent } from 'vscode-languageserver'; | ||
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
import workerpool from 'workerpool'; | ||
import { LinterTask, LintWorker } from './lint-worker'; | ||
|
||
const pool = workerpool.pool(join(__dirname, 'lint-worker.js'), { | ||
minWorkers: 2, | ||
workerTerminateTimeout: 2000, | ||
}); | ||
|
||
let lastSemanticJob: LinterTask | undefined; | ||
|
||
async function rawLintDocument( | ||
change: TextDocumentChangeEvent<TextDocument>, | ||
sendDiagnostics: (diagnostics: Diagnostic[]) => void, | ||
) { | ||
const { document } = change; | ||
|
||
const query = document.getText(); | ||
if (query.length === 0) { | ||
return; | ||
} | ||
|
||
const syntaxErrors = validateSyntax(query, {}); | ||
|
||
sendDiagnostics(syntaxErrors); | ||
|
||
if (syntaxErrors.length === 0) { | ||
try { | ||
if (lastSemanticJob !== undefined && !lastSemanticJob.resolved) { | ||
void lastSemanticJob.cancel(); | ||
} | ||
|
||
const proxyWorker = (await pool.proxy()) as unknown as LintWorker; | ||
lastSemanticJob = proxyWorker.validateSemantics(query); | ||
const result = await lastSemanticJob; | ||
|
||
sendDiagnostics( | ||
result.map((el) => findEndPosition(el, parserWrapper.parsingResult)), | ||
); | ||
} catch (err) { | ||
if (!(err instanceof workerpool.Promise.CancellationError)) { | ||
console.error(err); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const lintDocument = debounce(rawLintDocument, 600, { | ||
leading: false, | ||
trailing: true, | ||
}); | ||
|
||
export const cleanupWorkers = () => { | ||
void pool.terminate(); | ||
}; |
This file contains 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
Oops, something went wrong.