when capping decoration events pick somewhat smarter, https://github.com/microsoft/vscode/issues/108292

This commit is contained in:
Johannes Rieken
2020-10-23 20:50:19 +02:00
parent 4cc712b957
commit adf57aa968
2 changed files with 46 additions and 4 deletions

View File

@@ -12,7 +12,9 @@ import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { ILogService } from 'vs/platform/log/common/log';
import { asArray } from 'vs/base/common/arrays';
import { asArray, groupBy } from 'vs/base/common/arrays';
import { count } from 'vs/base/common/strings';
import { dirname } from 'vs/base/common/path';
interface ProviderData {
provider: vscode.FileDecorationProvider;
@@ -22,6 +24,7 @@ interface ProviderData {
export class ExtHostDecorations implements ExtHostDecorationsShape {
private static _handlePool = 0;
private static _maxEventSize = 250;
readonly _serviceBrand: undefined;
private readonly _provider = new Map<number, ProviderData>();
@@ -40,9 +43,34 @@ export class ExtHostDecorations implements ExtHostDecorationsShape {
this._proxy.$registerDecorationProvider(handle, extensionId.value);
const listener = provider.onDidChange(e => {
this._proxy.$onDidChange(handle, !e || (Array.isArray(e) && e.length > 250)
? null
: asArray(e));
if (!e) {
this._proxy.$onDidChange(handle, null);
return;
}
let array = asArray(e);
if (array.length <= ExtHostDecorations._maxEventSize) {
this._proxy.$onDidChange(handle, array);
return;
}
// too many resources per event. pick one resource per folder, starting
// with parent folders
const mapped = array.map(uri => ({ uri, rank: count(uri.path, '/') }));
const groups = groupBy(mapped, (a, b) => a.rank - b.rank);
let picked: URI[] = [];
outer: for (let uris of groups) {
let lastDirname: string | undefined;
for (let obj of uris) {
let myDirname = dirname(obj.uri.path);
if (lastDirname !== myDirname) {
lastDirname = myDirname;
if (picked.push(obj.uri) >= ExtHostDecorations._maxEventSize) {
break outer;
}
}
}
}
this._proxy.$onDidChange(handle, picked);
});
return new Disposable(() => {