Merge pull request #40953 from weswigham/improve-completions-large-literal-perf

Improve the performance of requesting completions within a massive array literal
This commit is contained in:
Wesley Wigham authored and GitHub committed 2020-10-07 12:44:20 -07:00
commit 4dc7e59248
3 files changed
+36 -3

No files matched your search

+2 -2
View File
@@ -1195,7 +1195,7 @@ namespace ts {
* @param keyComparer A callback used to compare two keys in a sorted array.
* @param offset An offset into `array` at which to start the search.
*/
export function binarySearchKey<T, U>(array: readonly T[], key: U, keySelector: (v: T) => U, keyComparer: Comparer<U>, offset?: number): number {
export function binarySearchKey<T, U>(array: readonly T[], key: U, keySelector: (v: T, i: number) => U, keyComparer: Comparer<U>, offset?: number): number {
if (!some(array)) {
return -1;
}
@@ -1204,7 +1204,7 @@ namespace ts {
let high = array.length - 1;
while (low <= high) {
const middle = low + ((high - low) >> 1);
const midKey = keySelector(array[middle]);
const midKey = keySelector(array[middle], middle);
switch (keyComparer(midKey, key)) {
case Comparison.LessThan:
low = middle + 1;
+15 -1
View File
@@ -1173,7 +1173,21 @@ namespace ts {
}
const children = n.getChildren(sourceFile);
for (let i = 0; i < children.length; i++) {
const i = binarySearchKey(children, position, (_, i) => i, (middle, _) => {
// This last callback is more of a selector than a comparator -
// `EqualTo` causes the `middle` result to be returned
// `GreaterThan` causes recursion on the left of the middle
// `LessThan` causes recursion on the right of the middle
if (position < children[middle].end) {
// first element whose end position is greater than the input position
if (!children[middle - 1] || position >= children[middle - 1].end) {
return Comparison.EqualTo;
}
return Comparison.GreaterThan;
}
return Comparison.LessThan;
});
if (i >= 0 && children[i]) {
const child = children[i];
// Note that the span of a node's tokens is [node.getStart(...), node.end).
// Given that `position < child.end` and child has constituent tokens, we distinguish these cases:
@@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />
/////*
//// Route exported from CloudMade;
////
//// Map data used is Copyright (c) OpenStreetMap contributors 2010
//// OpenStreetMap® is open data, licensed under the
//// Open Data Commons Open Database License (ODbL) by
//// the OpenStreetMap Foundation (OSMF).
////
//// See full license: https://www.openstreetmap.org/copyright
////*/
////var route = [[51.452339,-0.26291],[51.452011,-0.26479],[51.451839,-0.26624],[51.45187,-0.26706],[51.451881,-0.26733],[51.452049,-0.26734],[51.453098,-0.26734],[51.453838,-0.26717],[51.454849,-0.267],[51.45575,-0.26704],[51.45631,-0.26723],[51.456402,-0.26729],[51.456669,-0.26745],[51.45689,-0.26755],[51.457001,-0.26758],[51.45797,-0.26776],[51.458359,-0.26786],[51.459019,-0.26783],[51.459629,-0.26785],[51.459888,-0.26809],[51.460178,-0.26845],[51.46077,-0.26841],[51.461102,-0.26838],[51.461479,-0.2685],[51.46159,-0.26848],[51.462479,-0.26776],[51.462921,-0.26766],[51.463291,-0.26754],[51.463558,-0.26736],[51.46373,-0.26728],[51.464291,-0.26676],[51.464432,-0.26675],[51.464722,-0.26671],[51.464821,-0.2657],[51.46484,-0.2655],[51.464851,-0.26504],[51.46489,-0.26456],[51.464951,-0.26397],[51.464981,-0.26357],[51.46497,-0.26344],[51.465031,-0.26294],[51.46508,-0.26224],[51.465111,-0.26179],[51.46513,-0.26157],[51.465149,-0.261],[51.465149,-0.26077],[51.465149,-0.26051],[51.465149,-0.26011],[51.46513,-0.25982],[51.46513,-0.25955],[51.46513,-0.25929],[51.465111,-0.25872],[51.46513,-0.2583],[51.46513,-0.25771],[51.465141,-0.25753],[51.46516,-0.25675],[51.46516,-0.25658],[51.46516,-0.25647],[51.465179,-0.25574],[51.465191,-0.25525],[51.465199,-0.25486],[51.46521,-0.25455],[51.46521,-0.25413],[51.46524,-0.25293],[51.465229,-0.25186],[51.465191,-0.25085],[51.46513,-0.25001],[51.46508,-0.24926],[51.465069,-0.24862],[51.465111,-0.24775],[51.465149,-0.2472],[51.465172,-0.24675],[51.46524,-0.24571],[51.465279,-0.24482],[51.465321,-0.24423],[51.465229,-0.24372],[51.465149,-0.24266],[51.465118,-0.24208],[51.465069,-0.24147],[51.464939,-0.24028],[51.464821,-0.2395],[51.46476,-0.2389],[51.464729,-0.23852],[51.464642,-0.23755],[51.464569,-0.23693],[51.464481,-0.2365],[51.464371,-0.23557],[51.464211,-0.23437],[51.46418,-0.23421],[51.464001,-0.23334],[51.463959,-0.23316],[51.463829,-0.23253],[51.463779,-0.23235],[51.463699,-0.23189],[51.463661,-0.2317],[51.463589,-0.23136],[51.463539,-0.23106],[51.463402,-0.23025],[51.463341,-0.2299],[51.463249,-0.22924],[51.463139,-0.22838],[51.46312,-0.22823],[51.463001,-0.22726],[51.462959,-0.22698],[51.462891,-0.22645],[51.462769,-0.22551],[51.462761,-0.22516],[51.462681,-0.22436],[51.46262,-0.224],[51.462521,-0.22297],[51.462421,-0.22247],[51.462181,-0.22183],[51.462009,-0.22149],[51.461731,-0.22074],[51.461399,-0.2196],[51.461361,-0.21948],[51.46122,-0.21878],[51.461109,-0.21824],[51.460979,-0.2175],[51.460789,-0.21715],[51.46069,-0.21685],[51.460522,-0.21596],[51.4604,-0.21533],[51.460361,-0.21511],[51.460251,-0.21458],[51.46022,-0.2144],[51.460159,-0.21411],[51.460121,-0.21389],[51.46011,-0.2138],[51.459961,-0.21308],[51.459942,-0.21294],[51.459702,-0.21186],[51.459702,-0.21184],[51.45948,-0.21112],[51.459259,-0.21038],[51.459011,-0.20963],[51.45892,-0.2094],[51.458809,-0.2091],[51.458759,-0.20898],[51.45858,-0.20853],[51.458328,-0.20795],[51.458179,-0.2076],[51.458141,-0.20751],[51.458099,-0.20743],[51.457981,-0.2072],[51.45771,-0.20668],[51.4575,-0.20638],[51.457321,-0.20614],[51.45718,-0.20596],[51.457088,-0.20584],[51.456921,-0.20558],[51.456829,-0.20541],[51.456772,-0.20522],[51.45676,-0.20518],[51.456749,-0.20509],[51.45673,-0.20469],[51.456718,-0.20466],[51.456699,-0.20425],[51.456692,-0.20391],[51.456692,-0.20371],[51.456661,-0.20284],[51.456661,-0.20272],[51.456661,-0.20254],[51.456669,-0.20231],[51.456692,-0.20178],[51.456699,-0.20148],[51.45673,-0.20116],[51.45676,-0.20077],[51.45686,-0.19978],[51.45697,-0.19857],[51.457001,-0.19826],[51.457039,-0.19806],[51.45705,-0.19793],[51.457142,-0.19781],[51.457211,-0.19776],[51.45742,-0.19785],[51.45763,-0.19794],[51.45776,-0.19795],[51.457829,-0.19791],[51.45789,-0.19784],[51.458,-0.19751],[51.458172,-0.19697],[51.458271,-0.19654],[51.458439,-0.19585],[51.458599,-0.19507],[51.45863,-0.1949],[51.458729,-0.19437],[51.458809,-0.19394],[51.45892,-0.19318],[51.45892,-0.1926],[51.458839,-0.19206],[51.458858,-0.19189],[51.45887,-0.1917],[51.459049,-0.19117],[51.45916,-0.19078],[51.459148,-0.19065],[51.45908,-0.19055],[51.458679,-0.19041],[51.458511,-0.19034],[51.458271,-0.19026],[51.457939,-0.19013],[51.457329,-0.1899],[51.457199,-0.18985],[51.456829,-0.18972],[51.457069,-0.18858],[51.457142,-0.18824],[51.457211,-0.18785],[51.45731,-0.18732],[51.457581,-0.1857],[51.457649,-0.18525],[51.457878,-0.18476],[51.45797,-0.18457],[51.45829,-0.18387],[51.45866,-0.18305],[51.458771,-0.18276],[51.458801,-0.18269],[51.4589,-0.18243],[51.458981,-0.18222],[51.45911,-0.1819],[51.459229,-0.1815],[51.459358,-0.18094],[51.459431,-0.18064],[51.45956,-0.18014],[51.459518,-0.18],[51.459469,-0.17984],[51.45882,-0.1796],[51.458431,-0.17945],[51.458351,-0.17935],[51.458279,-0.17924],[51.458309,-0.17861],[51.458401,-0.17714],[51.458511,-0.17525],[51.45853,-0.17515],[51.45858,-0.17493],[51.458912,-0.17401],[51.459,-0.17374],[51.459179,-0.1732],[51.45929,-0.17292],[51.459461,-0.17245],[51.459579,-0.1721],[51.459919,-0.17123],[51.460232,-0.17037],[51.4604,-0.1696 Line truncated
verify.completions({
marker: "",
excludes: [""]
}); // There should be _no_ completions, but we actually only wanna check this doesn't spin forever anyway