MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

remove fast property cache and simplify cache invalidation

+8 -64
+1 -1
meson.build
··· 79 79 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 80 80 81 81 version_conf = configuration_data() 82 - version_conf.set('ANT_VERSION', '0.2.2.17') 82 + version_conf.set('ANT_VERSION', '0.2.2.18') 83 83 version_conf.set('ANT_GIT_HASH', git_hash) 84 84 version_conf.set('ANT_BUILD_DATE', build_date) 85 85
+7 -63
src/ant.c
··· 210 210 struct interned_string *next; 211 211 } interned_string_t; 212 212 213 - typedef struct { 214 - uint64_t combined_key; 215 - jsoff_t prop_offset; 216 - UT_hash_handle hh; 217 - } fast_prop_cache_t; 218 - 219 213 typedef struct koff_intern { 220 214 jsoff_t koff; 221 215 const char *interned; ··· 224 218 225 219 #define INTERN_BUCKETS 16384 226 220 static interned_string_t *intern_buckets[INTERN_BUCKETS]; 227 - static fast_prop_cache_t *fast_cache = NULL; 221 + 228 222 #define KOFF_BUCKETS 16384 229 223 static koff_intern_t *koff_buckets[KOFF_BUCKETS]; 230 224 ··· 2894 2888 koff_cache[slot].interned = interned; 2895 2889 } 2896 2890 2897 - static inline uint64_t make_cache_key(jsoff_t obj_offset, uint32_t str_hash) { 2898 - return ((uint64_t)obj_offset << 32) | str_hash; 2899 - } 2900 - 2901 - static void fast_cache_property(jsoff_t obj_offset, const char *key, size_t key_len, jsoff_t prop_offset) { 2902 - if (key_len > 63) return; 2903 - 2904 - uint64_t str_hash = hash_key(key, key_len); 2905 - uint64_t combined = make_cache_key(obj_offset, (uint32_t)str_hash); 2906 - 2907 - fast_prop_cache_t *entry = NULL; 2908 - HASH_FIND(hh, fast_cache, &combined, sizeof(uint64_t), entry); 2909 - 2910 - if (!entry) { 2911 - entry = (fast_prop_cache_t *)malloc(sizeof(fast_prop_cache_t)); 2912 - if (!entry) return; 2913 - entry->combined_key = combined; 2914 - HASH_ADD(hh, fast_cache, combined_key, sizeof(uint64_t), entry); 2915 - } 2916 - entry->prop_offset = prop_offset; 2917 - } 2918 - 2919 - static jsoff_t fast_cache_lookup(jsoff_t obj_offset, const char *key, size_t key_len) { 2920 - if (key_len > 63) return 0; 2921 - 2922 - uint64_t str_hash = hash_key(key, key_len); 2923 - uint64_t combined = make_cache_key(obj_offset, (uint32_t)str_hash); 2924 - 2925 - fast_prop_cache_t *entry = NULL; 2926 - HASH_FIND(hh, fast_cache, &combined, sizeof(uint64_t), entry); 2927 - if (entry) return entry->prop_offset; 2928 - return 0; 2929 - } 2930 - 2931 - static void invalidate_obj_cache(jsoff_t obj_offset) { 2932 - fast_prop_cache_t *entry, *tmp; 2933 - HASH_ITER(hh, fast_cache, entry, tmp) { 2934 - if ((entry->combined_key >> 32) == obj_offset) { 2935 - HASH_DEL(fast_cache, entry); 2936 - free(entry); 2937 - } 2938 - } 2939 - } 2940 - 2941 - static void invalidate_prop_cache_for_obj(jsoff_t obj_offset) { 2891 + static void invalidate_prop_cache(jsoff_t obj_offset) { 2942 2892 for (uint32_t i = 0; i < INTERN_PROP_CACHE_SIZE; i++) { 2943 2893 if (intern_prop_cache[i].obj_off == obj_offset) { 2944 2894 intern_prop_cache[i].obj_off = 0; ··· 2959 2909 2960 2910 if (b & ARRMASK) brk |= ARRMASK; 2961 2911 memcpy(&js->mem[head], &brk, sizeof(brk)); 2962 - invalidate_obj_cache(head); 2963 2912 2964 2913 jsoff_t klen = (loadoff(js, koff) >> 2) - 1; 2965 2914 const char *p = (char *) &js->mem[koff + sizeof(koff)]; ··· 8016 7965 jsoff_t current = loadoff(js, obj_off); 8017 7966 saveoff(js, obj_off, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 8018 7967 saveoff(js, prop_off, loadoff(js, prop_off) | GCMASK); 8019 - invalidate_obj_cache(obj_off); 8020 - invalidate_prop_cache_for_obj(obj_off); 7968 + invalidate_prop_cache(obj_off); 8021 7969 // js_gc(js); disabled 8022 7970 return js_mktrue(); 8023 7971 } ··· 8029 7977 jsoff_t current = loadoff(js, prev); 8030 7978 saveoff(js, prev, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 8031 7979 saveoff(js, prop_off, loadoff(js, prop_off) | GCMASK); 8032 - invalidate_obj_cache(obj_off); 8033 - invalidate_prop_cache_for_obj(obj_off); 7980 + invalidate_prop_cache(obj_off); 8034 7981 // js_gc(js); disabled 8035 7982 return js_mktrue(); 8036 7983 } ··· 8118 8065 saveoff(js, prev_prop_off, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 8119 8066 } 8120 8067 saveoff(js, prop_off, loadoff(js, prop_off) | GCMASK); 8121 - invalidate_obj_cache(owner_obj_off); 8122 - invalidate_prop_cache_for_obj(owner_obj_off); 8068 + invalidate_prop_cache(owner_obj_off); 8123 8069 // js_gc(js); disabled 8124 8070 } 8125 8071 (void) save_pos; ··· 20674 20620 jsoff_t current = loadoff(js, obj_off); 20675 20621 saveoff(js, obj_off, (deleted_next & ~3U) | (current & (GCMASK | CONSTMASK | 3U))); 20676 20622 saveoff(js, prop_off, loadoff(js, prop_off) | GCMASK); 20677 - invalidate_obj_cache(obj_off); 20678 - invalidate_prop_cache_for_obj(obj_off); 20623 + invalidate_prop_cache(obj_off); 20679 20624 return true; 20680 20625 } 20681 20626 ··· 20687 20632 jsoff_t prev_flags = loadoff(js, prev) & (GCMASK | CONSTMASK); 20688 20633 saveoff(js, prev, deleted_next | prev_flags); 20689 20634 saveoff(js, prop_off, loadoff(js, prop_off) | GCMASK); 20690 - invalidate_obj_cache(obj_off); 20691 - invalidate_prop_cache_for_obj(obj_off); 20635 + invalidate_prop_cache(obj_off); 20692 20636 return true; 20693 20637 } 20694 20638 prev = next_prop;