Skip to content

Commit 2f76846

Browse files
committed
Work in progress
1 parent 9fddfde commit 2f76846

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src-input/duk_heap.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
/* Slotcache is used to speeding up object property lookups without
145145
* caching a property value.
146146
*/
147-
#define DUK_HEAP_SLOTCACHE_SIZE 8192
147+
#define DUK_HEAP_SLOTCACHE_SIZE 256
148148

149149
/* helper to insert a (non-string) heap object into heap allocated list */
150150
#define DUK_HEAP_INSERT_INTO_HEAP_ALLOCATED(heap,hdr) duk_heap_insert_into_heap_allocated((heap),(hdr))
@@ -533,8 +533,10 @@ DUK_INTERNAL void duk_heap_strtable_dump(duk_heap *heap);
533533
DUK_INTERNAL_DECL void duk_heap_strcache_string_remove(duk_heap *heap, duk_hstring *h);
534534
DUK_INTERNAL_DECL duk_uint_fast32_t duk_heap_strcache_offset_char2byte(duk_hthread *thr, duk_hstring *h, duk_uint_fast32_t char_offset);
535535

536+
/* FIXME: duk_small_uint_t? */
536537
DUK_INTERNAL_DECL duk_uint32_t duk_heap_slotcache_lookup(duk_heap *heap, duk_hobject *obj, duk_hstring *key);
537538
DUK_INTERNAL_DECL void duk_heap_slotcache_insert(duk_heap *heap, duk_hobject *obj, duk_hstring *key, duk_uint32_t slot);
539+
DUK_INTERNAL_DECL duk_uint32_t duk_heap_slotcache_getkey(duk_hobject *obj, duk_hstring *key);
538540

539541
#if defined(DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS)
540542
DUK_INTERNAL_DECL void *duk_default_alloc_function(void *udata, duk_size_t size);

src-input/duk_heap_slotcache.c

+23-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44

55
#include "duk_internal.h"
66

7+
/* FIXME: check if it's useful to compute the slotcache key only once in property code
8+
* (live range is not trivial so maybe not).
9+
*/
10+
11+
DUK_LOCAL DUK_ALWAYS_INLINE duk_uint32_t duk__slotcache_compute_key(duk_hobject *obj, duk_hstring *key) {
12+
DUK_ASSERT(obj != NULL);
13+
DUK_ASSERT(key != NULL);
14+
15+
return (((duk_uint32_t) obj) ^ DUK_HSTRING_GET_HASH(key)) & (DUK_HEAP_SLOTCACHE_SIZE - 1);
16+
}
17+
18+
DUK_INTERNAL duk_uint32_t duk_heap_slotcache_getkey(duk_hobject *obj, duk_hstring *key) {
19+
DUK_ASSERT(obj != NULL);
20+
DUK_ASSERT(key != NULL);
21+
22+
return duk__slotcache_compute_key(obj, key);
23+
}
24+
725
DUK_INTERNAL duk_uint32_t duk_heap_slotcache_lookup(duk_heap *heap, duk_hobject *obj, duk_hstring *key) {
826
duk_uint32_t idx;
927
duk_slotcache_entry *ent;
@@ -14,8 +32,8 @@ DUK_INTERNAL duk_uint32_t duk_heap_slotcache_lookup(duk_heap *heap, duk_hobject
1432

1533
/* FIXME: assert: hashlimit <= 256 */
1634

17-
idx = ((duk_uint32_t) obj) ^ DUK_HSTRING_GET_HASH(key);
18-
ent = heap->slotcache + (idx & (DUK_HEAP_SLOTCACHE_SIZE - 1));
35+
idx = duk__slotcache_compute_key(obj, key);
36+
ent = heap->slotcache + idx;
1937
return ent->slot;
2038
}
2139

@@ -25,10 +43,10 @@ DUK_INTERNAL void duk_heap_slotcache_insert(duk_heap *heap, duk_hobject *obj, du
2543

2644
/* FIXME: assert: hashlimit <= 256 */
2745
/* FIXME: skip check if hash part present and hashlimit correct */
28-
if (DUK_UNLIKELY(slot >= DUK_UINT16_MAX)) {
46+
if (DUK_UNLIKELY(slot >= DUK_UINT8_MAX)) {
2947
return;
3048
}
31-
idx = ((duk_uint32_t) obj) ^ DUK_HSTRING_GET_HASH(key);
32-
ent = heap->slotcache + (idx & (DUK_HEAP_SLOTCACHE_SIZE - 1));
49+
idx = duk__slotcache_compute_key(obj, key);
50+
ent = heap->slotcache + idx;
3351
ent->slot = (duk_uint16_t) slot;
3452
}

src-input/duk_hobject_props.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,9 @@ DUK_INTERNAL void duk_hobject_find_existing_entry(duk_heap *heap, duk_hobject *o
11821182
slot = duk_heap_slotcache_lookup(heap, obj, key);
11831183
if (slot < DUK_HOBJECT_GET_ENEXT(obj)) {
11841184
if (DUK_HOBJECT_E_GET_KEY(heap, obj, slot) == key) {
1185-
DUK_D(DUK_DPRINT("slot cache hit: %p %p -> %ld", (void *) obj, (void *) key, (long) slot));
1185+
DUK_D(DUK_DPRINT("slot cache hit: %p %p %!O -> %ld (slotcache lookup key %lu)",
1186+
(void *) obj, (void *) key, key, (long) slot,
1187+
(unsigned long) duk_heap_slotcache_getkey(obj, key)));
11861188
*e_idx = slot;
11871189
*h_idx = -1;
11881190
return;
@@ -1193,7 +1195,9 @@ DUK_INTERNAL void duk_hobject_find_existing_entry(duk_heap *heap, duk_hobject *o
11931195
n = DUK_HOBJECT_GET_ENEXT(obj);
11941196
for (i = 0; i < n; i++) {
11951197
if (h_keys_base[i] == key) {
1196-
DUK_D(DUK_DPRINT("slot cache insert: %p %p -> %ld", (void *) obj, (void *) key, (long) i));
1198+
DUK_D(DUK_DPRINT("slot cache insert: %p %p %!O -> %ld (slotcache lookup key %lu)",
1199+
(void *) obj, (void *) key, key, (long) i,
1200+
(unsigned long) duk_heap_slotcache_getkey(obj, key)));
11971201
duk_heap_slotcache_insert(heap, obj, key, i);
11981202
*e_idx = i;
11991203
*h_idx = -1;

0 commit comments

Comments
 (0)