Skip to content
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

fix: limit decorations to prevent editor slowdown #590

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@ export class Extension implements RunHooks {
}
});
}

if (completedDecorations.length > 1000) // too many decorations slow down the editor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a 100? I can't imagine anyone reading more than five :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This limit is per-file, so 100 will be used up quickly. And we don't know which ones the user wants to read. So i'd stay high enough that we only prevent the performance bottleneck, and nothing else.

break;
}

editor.setDecorations(this._activeStepDecorationType, activeDecorations);
Expand Down
23 changes: 23 additions & 0 deletions tests/decorations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,26 @@ test('should highlight steps while running', async ({ activate }) => {
},
]);
});

test('should limit highlights', async ({ activate }) => {
const { vscode, testController } = await activate({
'playwright.config.js': `module.exports = { testDir: 'tests' }`,
'tests/test.spec.ts': `
import { test, expect } from '@playwright/test';
test('pass', async () => {
for (let i = 0; i < 2000; i++) {
expect(i).toBe(i);
}
});
`,
});

await vscode.openEditors('**/test.spec.ts');
await new Promise(f => testController.onDidChangeTestItem(f));

await testController.run();

const decorationsLog = vscode.window.activeTextEditor.renderDecorations(' ');
const lastState = decorationsLog.substring(decorationsLog.lastIndexOf('------'));
expect(lastState.split('\n').length).toBeLessThan(2000);
});
Loading