Browse Source

Merge pull request #1677 from svaarala/improve-strtable-stats

Add resize statistics for string table
pull/1679/head
Sami Vaarala 7 years ago
committed by GitHub
parent
commit
a128847e5b
  1. 2
      RELEASES.rst
  2. 7
      src-input/duk_heap.h
  3. 6
      src-input/duk_heap_markandsweep.c
  4. 12
      src-input/duk_heap_stringtable.c

2
RELEASES.rst

@ -3086,7 +3086,7 @@ Planned
guaranteed by the API and is mostly unnecessary (GH-1552)
* Add some statistics dumps to mark-and-sweep with debug logging enabled
(GH-1579, GH-1640)
(GH-1579, GH-1640, GH-1677)
* Add DUK_CONSOLE_FLUSH flag to extras/duktape-console (GH-1587, GH-1588)

7
src-input/duk_heap.h

@ -572,8 +572,11 @@ struct duk_heap {
duk_int_t stats_ms_try_count;
duk_int_t stats_ms_skip_count;
duk_int_t stats_ms_emergency_count;
duk_int_t stats_intern_hit;
duk_int_t stats_intern_miss;
duk_int_t stats_strtab_intern_hit;
duk_int_t stats_strtab_intern_miss;
duk_int_t stats_strtab_resize_check;
duk_int_t stats_strtab_resize_grow;
duk_int_t stats_strtab_resize_shrink;
duk_int_t stats_object_realloc_props;
duk_int_t stats_object_abandon_array;
duk_int_t stats_getownpropdesc_count;

6
src-input/duk_heap_markandsweep.c

@ -1063,8 +1063,10 @@ DUK_LOCAL void duk__dump_stats(duk_heap *heap) {
DUK_D(DUK_DPRINT("stats mark-and-sweep: try_count=%ld, skip_count=%ld, emergency_count=%ld",
(long) heap->stats_ms_try_count, (long) heap->stats_ms_skip_count,
(long) heap->stats_ms_emergency_count));
DUK_D(DUK_DPRINT("stats string intern: hit=%ld, miss=%ld",
(long) heap->stats_intern_hit, (long) heap->stats_intern_miss));
DUK_D(DUK_DPRINT("stats stringtable: intern_hit=%ld, intern_miss=%ld, resize_check=%ld, resize_grow=%ld, resize_shrink=%ld",
(long) heap->stats_strtab_intern_hit, (long) heap->stats_strtab_intern_miss,
(long) heap->stats_strtab_resize_check, (long) heap->stats_strtab_resize_grow,
(long) heap->stats_strtab_resize_shrink));
DUK_D(DUK_DPRINT("stats object: realloc_props=%ld, abandon_array=%ld",
(long) heap->stats_object_realloc_props, (long) heap->stats_object_abandon_array));
DUK_D(DUK_DPRINT("stats getownpropdesc: count=%ld, hit=%ld, miss=%ld",

12
src-input/duk_heap_stringtable.c

@ -286,6 +286,8 @@ DUK_LOCAL void duk__strtable_grow_inplace(duk_heap *heap) {
DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */
DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL);
DUK_STATS_INC(heap, stats_strtab_resize_grow);
new_st_size = heap->st_size << 1U;
DUK_ASSERT(new_st_size > heap->st_size); /* No overflow. */
@ -402,6 +404,8 @@ DUK_LOCAL void duk__strtable_shrink_inplace(duk_heap *heap) {
DUK_ASSERT((heap->st_size & (heap->st_size - 1)) == 0); /* 2^N */
DUK_ASSERT(DUK__GET_STRTABLE(heap) != NULL);
DUK_STATS_INC(heap, stats_strtab_resize_shrink);
new_st_size = heap->st_size >> 1U;
/* Combine two buckets into a single one. When we shrink, one hash
@ -472,6 +476,8 @@ DUK_LOCAL DUK_COLD DUK_NOINLINE void duk__strtable_resize_check(duk_heap *heap)
DUK_ASSERT(heap->strtable != NULL);
#endif
DUK_STATS_INC(heap, stats_strtab_resize_check);
/* Prevent recursive resizing. */
if (DUK_UNLIKELY(heap->st_resizing)) {
DUK_D(DUK_DPRINT("prevent recursive strtable resize"));
@ -725,7 +731,7 @@ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uin
DUK_HSTRING_GET_BYTELEN(h) == blen &&
DUK_MEMCMP((const void *) str, (const void *) DUK_HSTRING_GET_DATA(h), (size_t) blen) == 0) {
/* Found existing entry. */
DUK_STATS_INC(heap, stats_intern_hit);
DUK_STATS_INC(heap, stats_strtab_intern_hit);
return h;
}
h = h->hdr.h_next;
@ -739,14 +745,14 @@ DUK_INTERNAL duk_hstring *duk_heap_strtable_intern(duk_heap *heap, const duk_uin
#if defined(DUK_USE_ROM_STRINGS)
h = duk__strtab_romstring_lookup(heap, str, blen, strhash);
if (h != NULL) {
DUK_STATS_INC(heap, stats_intern_hit);
DUK_STATS_INC(heap, stats_strtab_intern_hit);
return h;
}
#endif
/* Not found in string table; insert. */
DUK_STATS_INC(heap, stats_intern_miss);
DUK_STATS_INC(heap, stats_strtab_intern_miss);
h = duk__strtable_do_intern(heap, str, blen, strhash);
return h; /* may be NULL */
}

Loading…
Cancel
Save