Njs: accidental slow path in njs_array_iterator()

Created on 28 Aug 2019  路  1Comment  路  Source: nginx/njs

@lexborisov
@xeioex

After the recent changes, I've noticed a 3x performance slowdown in this test.

Reason:

>> var a = Array(10**6).fill(1);
undefined
>> console.time(); a.reduce((x) => x, 0); console.timeEnd();
default: 38.690147ms
undefined
>> console.time(); a.reduce((x) => x, 0); console.timeEnd();
default: 39.083297ms
undefined
>> a.length
1000000
// now njs_object_hash_is_empty(value) is false o_O
>> console.time(); a.reduce((x) => x, 0); console.timeEnd();
default: 113.228310ms
undefined
>> console.time(); a.reduce((x) => x, 0); console.timeEnd();
default: 111.459864ms
undefined
>> console.time(); a.reduce((x) => x, 0); console.timeEnd();
default: 112.251771ms
undefined

BTW, typo?
njs_array_interator_args_t -> njs_array_iterator_args_t

bug performance

Most helpful comment

@drsm

Thanks for reporting.

now njs_object_hash_is_empty(value) is false o_O

since https://hg.nginx.org/njs/rev/df385232d2af "length" NJS_PROPERTY_HANDLER was copied to private array hash at the moment it was accessed.

>All comments

@drsm

Thanks for reporting.

now njs_object_hash_is_empty(value) is false o_O

since https://hg.nginx.org/njs/rev/df385232d2af "length" NJS_PROPERTY_HANDLER was copied to private array hash at the moment it was accessed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xeioex picture xeioex  路  3Comments

drsm picture drsm  路  3Comments

drsm picture drsm  路  4Comments

pavelsevcik picture pavelsevcik  路  4Comments

xeioex picture xeioex  路  3Comments