perf: don't create holey arrays (#32155)

Don't use `Array` constructor with the size value (ex. `new Array(5)`) - this will create a `HOLEY_ELEMENTS` array (even if this array is filled in later on!);

https://v8.dev/blog/elements-kinds
https://stackoverflow.com/questions/32054170/how-to-resize-an-array

PR Close #32155
This commit is contained in:
Miško Hevery
2019-08-15 13:42:17 -07:00
committed by Andrew Kushnir
parent c957dfc167
commit 64770571b2
32 changed files with 137 additions and 83 deletions

View File

@ -7,10 +7,10 @@
*/
import {Type, isType} from '../interface/type';
import {newArray} from '../util/array_utils';
import {ANNOTATIONS, PARAMETERS, PROP_METADATA} from '../util/decorators';
import {global} from '../util/global';
import {stringify} from '../util/stringify';
import {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
import {GetterFn, MethodFn, SetterFn} from './types';
@ -53,9 +53,9 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
let result: any[][];
if (typeof paramTypes === 'undefined') {
result = new Array(paramAnnotations.length);
result = newArray(paramAnnotations.length);
} else {
result = new Array(paramTypes.length);
result = newArray(paramTypes.length);
}
for (let i = 0; i < result.length; i++) {
@ -120,7 +120,7 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
// based on function.length.
// Note: We know that this is a real constructor as we checked
// the content of the constructor above.
return new Array((<any>type.length)).fill(undefined);
return newArray<any[]>(type.length);
}
parameters(type: Type<any>): any[][] {