Skip to content

Commit d60eae7

Browse files
committed
Add minimum size check for abandoning array
1 parent f96bcd0 commit d60eae7

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

config/config-options/DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ tags:
55
- performance
66
- lowmemory
77
description: >
8-
Abandon array part if its density is below L. The limit L is expressed as
8+
Abandon array part if its density is below L and array is larger than
9+
DUK_USE_HOBJECT_ARRAY_ABANDON_MINSIZE. The limit L is expressed as
910
a .3 fixed point point, e.g. 2 means 2/8 = 25%.
1011
1112
The default limit is quite low: one array entry with packed duk_tval is 8
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
define: DUK_USE_HOBJECT_ARRAY_ABANDON_MINSIZE
2+
introduced: 2.5.0
3+
default: 257
4+
tags:
5+
- performance
6+
- lowmemory
7+
description: >
8+
Minimum array size required for array to be abandoned. For example, a value
9+
of 257 means arrays up to 256 long are never abandoned. The default value
10+
ensures 8-bit lookups are not abandoned even if sparse or initialized in
11+
random order.

config/examples/low_memory.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ DUK_USE_HSTRING_LAZY_CLEN: false # non-lazy charlen is smaller
8181
# lower memory targets usually drop hash part support entirely.
8282
DUK_USE_HOBJECT_HASH_PROP_LIMIT: 64
8383

84+
DUK_USE_HOBJECT_ARRAY_ABANDON_MINSIZE: 32
85+
8486
# Disable freelist caching.
8587
DUK_USE_CACHE_ACTIVATION: false
8688
DUK_USE_CACHE_CATCHER: false

src-input/duk_hobject_props.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ DUK_LOCAL duk_bool_t duk__abandon_array_density_check(duk_uint32_t a_used, duk_u
326326

327327
/* Fast check for extending array: check whether or not a slow density check is required. */
328328
DUK_LOCAL duk_bool_t duk__abandon_array_slow_check_required(duk_uint32_t arr_idx, duk_uint32_t old_size) {
329+
duk_uint32_t new_size_min;
330+
329331
/*
330332
* In a fast check we assume old_size equals old_used (i.e., existing
331333
* array is fully dense).
@@ -347,7 +349,9 @@ DUK_LOCAL duk_bool_t duk__abandon_array_slow_check_required(duk_uint32_t arr_idx
347349
* arr_idx > limit'' * ((old_size + 7) / 8)
348350
*/
349351

350-
return (arr_idx > DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT * ((old_size + 7) >> 3));
352+
new_size_min = arr_idx + 1;
353+
return (new_size_min >= DUK_USE_HOBJECT_ARRAY_ABANDON_MINSIZE) &&
354+
(arr_idx > DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT * ((old_size + 7) >> 3));
351355
}
352356

353357
DUK_LOCAL duk_bool_t duk__abandon_array_check(duk_hthread *thr, duk_uint32_t arr_idx, duk_hobject *obj) {

0 commit comments

Comments
 (0)