-
-
Notifications
You must be signed in to change notification settings - Fork 91
Added performance tests #2697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Added performance tests #2697
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e642d0d
Started performance testing
AndreasArvidsson cefd428
Update
AndreasArvidsson d728c63
Update logging severity
AndreasArvidsson be23c5d
Updated thresholds
AndreasArvidsson bd26d73
update thresholds
AndreasArvidsson 0bee3b6
Refactor
AndreasArvidsson 556be56
More refactoring
AndreasArvidsson 839de24
more fixes
AndreasArvidsson 82764d7
More updates
AndreasArvidsson 3ccd81d
Update logging
AndreasArvidsson 510f4ad
Increase threshold
AndreasArvidsson c85540d
Added collection item
AndreasArvidsson 962dd94
Update comments
AndreasArvidsson 223157a
Update
AndreasArvidsson 637f9b6
Update comment
AndreasArvidsson d7a82a1
Use shorter test data for surrounding pairs
AndreasArvidsson c274f4e
Use full test for surrounding pairs
AndreasArvidsson ddaf0d5
Updated comment
AndreasArvidsson 6edea38
Merge branch 'main' into performance
AndreasArvidsson 1c5d4d5
Merge branch 'main' into performance
AndreasArvidsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
packages/cursorless-vscode-e2e/src/suite/performance.vscode.test.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import { | ||
asyncSafety, | ||
type ActionDescriptor, | ||
type ScopeType, | ||
type SimpleScopeTypeType, | ||
} from "@cursorless/common"; | ||
import { openNewEditor, runCursorlessCommand } from "@cursorless/vscode-common"; | ||
import assert from "assert"; | ||
import * as vscode from "vscode"; | ||
import { endToEndTestSetup } from "../endToEndTestSetup"; | ||
|
||
const testData = generateTestData(); | ||
const numLines = testData.split("\n").length; | ||
|
||
suite(`Performance: ${numLines} lines JSON`, async function () { | ||
endToEndTestSetup(this); | ||
|
||
let previousTitle = ""; | ||
|
||
this.beforeEach(function () { | ||
const title = this.currentTest!.title; | ||
if (title !== previousTitle) { | ||
console.log(` ${title}`); | ||
previousTitle = title; | ||
} | ||
}); | ||
|
||
const textBasedThreshold = 100; | ||
const parseTreeThreshold = 500; | ||
const surroundingPairThreshold = 30000; | ||
AndreasArvidsson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
AndreasArvidsson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
test( | ||
"Remove token", | ||
asyncSafety(() => removeToken(textBasedThreshold)), | ||
); | ||
|
||
const fixtures: [SimpleScopeTypeType | ScopeType, number][] = [ | ||
// Text based | ||
["character", textBasedThreshold], | ||
["word", textBasedThreshold], | ||
["token", textBasedThreshold], | ||
["identifier", textBasedThreshold], | ||
["line", textBasedThreshold], | ||
["sentence", textBasedThreshold], | ||
["paragraph", textBasedThreshold], | ||
["document", textBasedThreshold], | ||
["nonWhitespaceSequence", textBasedThreshold], | ||
// Parse tree based | ||
["string", parseTreeThreshold], | ||
["map", parseTreeThreshold], | ||
["collectionKey", parseTreeThreshold], | ||
["value", parseTreeThreshold], | ||
// Text based, but utilizes surrounding pair | ||
["boundedParagraph", surroundingPairThreshold], | ||
["boundedNonWhitespaceSequence", surroundingPairThreshold], | ||
["collectionItem", surroundingPairThreshold], | ||
// Surrounding pair | ||
[{ type: "surroundingPair", delimiter: "any" }, surroundingPairThreshold], | ||
[ | ||
{ type: "surroundingPair", delimiter: "curlyBrackets" }, | ||
surroundingPairThreshold, | ||
], | ||
]; | ||
|
||
for (const [scope, threshold] of fixtures) { | ||
const [scopeType, title] = getScopeTypeAndTitle(scope); | ||
test( | ||
`Select ${title}`, | ||
asyncSafety(() => selectScopeType(scopeType, threshold)), | ||
); | ||
} | ||
}); | ||
|
||
async function removeToken(threshold: number) { | ||
await testPerformance(threshold, { | ||
name: "remove", | ||
target: { | ||
type: "primitive", | ||
modifiers: [{ type: "containingScope", scopeType: { type: "token" } }], | ||
}, | ||
}); | ||
} | ||
|
||
async function selectScopeType(scopeType: ScopeType, threshold: number) { | ||
await testPerformance(threshold, { | ||
name: "setSelection", | ||
target: { | ||
type: "primitive", | ||
modifiers: [{ type: "containingScope", scopeType }], | ||
}, | ||
}); | ||
} | ||
|
||
async function testPerformance(threshold: number, action: ActionDescriptor) { | ||
const editor = await openNewEditor(testData, { languageId: "json" }); | ||
const position = new vscode.Position(editor.document.lineCount - 3, 5); | ||
const selection = new vscode.Selection(position, position); | ||
editor.selections = [selection]; | ||
editor.revealRange(selection); | ||
|
||
const start = performance.now(); | ||
|
||
await runCursorlessCommand({ | ||
version: 7, | ||
usePrePhraseSnapshot: false, | ||
action, | ||
}); | ||
pokey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const duration = Math.round(performance.now() - start); | ||
|
||
console.log(` ${duration} ms`); | ||
|
||
assert.ok( | ||
duration < threshold, | ||
`Duration ${duration}ms exceeds threshold ${threshold}ms`, | ||
); | ||
} | ||
|
||
function getScopeTypeAndTitle( | ||
scope: SimpleScopeTypeType | ScopeType, | ||
): [ScopeType, string] { | ||
if (typeof scope === "string") { | ||
return [{ type: scope }, scope]; | ||
} | ||
switch (scope.type) { | ||
case "surroundingPair": | ||
return [scope, `${scope.type}.${scope.delimiter}`]; | ||
} | ||
throw Error(`Unexpected scope type: ${scope.type}`); | ||
} | ||
|
||
function generateTestData(): string { | ||
const value = Object.fromEntries( | ||
new Array(100).fill("").map((_, i) => [i.toString(), "value"]), | ||
); | ||
const obj = Object.fromEntries( | ||
new Array(100).fill("").map((_, i) => [i.toString(), value]), | ||
); | ||
return JSON.stringify(obj, null, 2); | ||
} | ||
AndreasArvidsson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.