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.

improve event loop speeds

fix a little oopsie where I scanned the entire stack 1 billion times a second slowing the event loop from 7mil iter/5s to 17k iter/5s ... ๐Ÿ˜…

+46 -30
+6
include/internal.h
··· 209 209 uint32_t jit_active_depth; 210 210 #endif 211 211 212 + struct { 213 + ant_value_t *items; 214 + size_t len; 215 + size_t cap; 216 + } pending_rejections; 217 + 212 218 bool owns_mem; 213 219 bool fatal_error; 214 220 bool thrown_exists;
+37 -29
src/ant.c
··· 9920 9920 pd->value = val; 9921 9921 gc_write_barrier(js, js_obj_ptr(js_as_obj(p)), val); 9922 9922 pd->unhandled_reported = false; 9923 - 9923 + 9924 + if (js->pending_rejections.len >= js->pending_rejections.cap) { 9925 + size_t new_cap = js->pending_rejections.cap ? js->pending_rejections.cap * 2 : 16; 9926 + ant_value_t *ns = realloc(js->pending_rejections.items, new_cap * sizeof(*ns)); 9927 + if (ns) { js->pending_rejections.items = ns; js->pending_rejections.cap = new_cap; } 9928 + } 9929 + if (js->pending_rejections.len < js->pending_rejections.cap) 9930 + js->pending_rejections.items[js->pending_rejections.len++] = p; 9931 + 9924 9932 trigger_handlers(js, p); 9925 9933 } 9926 9934 ··· 12040 12048 free(js->c_roots); 12041 12049 js->c_roots = NULL; 12042 12050 js->c_root_count = js->c_root_cap = 0; 12051 + free(js->pending_rejections.items); 12052 + js->pending_rejections.items = NULL; 12053 + js->pending_rejections.len = js->pending_rejections.cap = 0; 12043 12054 12044 12055 js_pool_destroy(&js->pool.rope); 12045 12056 js_pool_destroy(&js->pool.symbol); ··· 12615 12626 iter->ctx = NULL; 12616 12627 } 12617 12628 12618 - static void check_unhandled_rejections_list(ant_t *js, ant_object_t *list) { 12619 - for (ant_object_t *obj = list; obj; obj = obj->next) { 12620 - ant_promise_state_t *pd = obj->promise_state; 12621 - if (!pd) continue; 12622 - if (pd->state != 2) continue; 12623 - if (pd->has_rejection_handler || pd->unhandled_reported) continue; 12624 - 12625 - if (vtype(pd->trigger_parent) == T_PROMISE) { 12626 - ant_promise_state_t *parent = get_promise_data(js, pd->trigger_parent, false); 12627 - if (parent && parent->has_rejection_handler) continue; 12628 - } 12629 - 12630 - if (js->fatal_error) { 12631 - js->thrown_exists = true; 12632 - js->thrown_value = pd->value; 12633 - print_uncaught_throw(js); 12634 - js_destroy(js); exit(1); 12629 + void js_check_unhandled_rejections(ant_t *js) { 12630 + size_t keep = 0; 12631 + 12632 + for (size_t i = 0; i < js->pending_rejections.len; i++) { 12633 + ant_value_t p = js->pending_rejections.items[i]; 12634 + ant_promise_state_t *pd = get_promise_data(js, p, false); 12635 + if (!pd || pd->has_rejection_handler || pd->unhandled_reported) continue; 12636 + 12637 + if (vtype(pd->trigger_parent) == T_PROMISE) { 12638 + ant_promise_state_t *parent = get_promise_data(js, pd->trigger_parent, false); 12639 + if (parent && parent->has_rejection_handler) continue; 12640 + } 12641 + 12642 + if (js->fatal_error) { 12643 + js->thrown_exists = true; 12644 + js->thrown_value = pd->value; 12645 + print_uncaught_throw(js); 12646 + js_destroy(js); exit(1); 12647 + } 12648 + 12649 + if (!js_fire_unhandled_rejection(js, p, pd->value)) 12650 + print_unhandled_promise_rejection(js, pd->value); 12651 + pd->unhandled_reported = true; 12635 12652 } 12636 - 12637 - ant_value_t promise_val = mkval(T_PROMISE, (uintptr_t)obj); 12638 - if (!js_fire_unhandled_rejection(js, promise_val, pd->value)) 12639 - print_unhandled_promise_rejection(js, pd->value); 12640 - pd->unhandled_reported = true; 12641 - }} 12642 - 12643 - void js_check_unhandled_rejections(ant_t *js) { 12644 - check_unhandled_rejections_list(js, js->objects); 12645 - check_unhandled_rejections_list(js, js->objects_old); 12646 - check_unhandled_rejections_list(js, js->permanent_objects); 12653 + 12654 + js->pending_rejections.len = keep; 12647 12655 } 12648 12656 12649 12657 void js_set_getter(ant_value_t obj, js_getter_fn getter) {
+3 -1
src/gc/objects.c
··· 437 437 gc_mark_value(js, ctx->prev_import_meta_prop); 438 438 } 439 439 440 + for (size_t i = 0; i < js->pending_rejections.len; i++) 441 + gc_mark_value(js, js->pending_rejections.items[i]); 442 + 440 443 gc_visit_roots(js, gc_mark_value); 441 444 gc_mark_timers(js, gc_mark_value); 442 445 gc_mark_ffi(js, gc_mark_value); ··· 482 485 void gc_object_free(ant_t *js, ant_object_t *obj) { 483 486 if (!obj) return; 484 487 if (obj->finalizer) obj->finalizer(js, obj); 485 - 486 488 obj->mark_epoch = ANT_GC_DEAD; 487 489 488 490 if (obj->shape) {