add compile time configs for tracy, mimalloc and qrencode

This commit is contained in:
2025-07-18 05:23:00 -05:00
parent 881407a64f
commit 7bfd244bf2
6 changed files with 116 additions and 27 deletions

View File

@@ -11,7 +11,9 @@
#include <sys/stat.h>
#include <time.h>
#ifdef HAVE_MIMALLOC
#include <mimalloc.h>
#endif
#ifdef __APPLE__
#include <sys/types.h>
@@ -185,7 +187,9 @@ void actor_free(cell_rt *actor)
SDL_UnlockMutex(actor->msg_mutex);
SDL_DestroyMutex(actor->msg_mutex);
#ifdef HAVE_MIMALLOC
mi_heap_destroy(actor->heap);
#endif
free(actor);
SDL_LockMutex(actors_mutex);
@@ -219,16 +223,26 @@ void *js_mi_malloc(JSMallocState *s, size_t sz) {
assert(sz != 0);
if (unlikely(s->malloc_size + sz > s->malloc_limit)) return NULL;
#ifdef HAVE_MIMALLOC
cell_rt *actor = (cell_rt*)s->opaque;
ptr = mi_heap_malloc(actor->heap, sz);
#else
ptr = malloc(sz);
#endif
if (!ptr) return NULL;
s->malloc_count++;
s->malloc_size += js_mi_malloc_usable_size(ptr) + MALLOC_OVERHEAD;
#ifdef TRACY_ENABLE
if (tracy_profiling_enabled)
if (tracy_profiling_enabled) {
#ifdef HAVE_MIMALLOC
cell_rt *actor = (cell_rt*)s->opaque;
TracyCAllocN(ptr, js_mi_malloc_usable_size(ptr) + MALLOC_OVERHEAD, actor->name);
#else
TracyCAllocN(ptr, js_mi_malloc_usable_size(ptr) + MALLOC_OVERHEAD, "actor");
#endif
}
#endif
return ptr;
@@ -242,17 +256,24 @@ void js_mi_free(JSMallocState *s, void *p) {
#ifdef TRACY_ENABLE
if (tracy_profiling_enabled) {
#ifdef HAVE_MIMALLOC
cell_rt *actor = s->opaque;
TracyCFreeN(p, actor->name);
#else
TracyCFreeN(p, "actor");
#endif
}
#endif
#ifdef HAVE_MIMALLOC
mi_free(p);
#else
free(p);
#endif
}
void *js_mi_realloc(JSMallocState *s, void *p, size_t sz) {
size_t old_size;
cell_rt *actor = (cell_rt*)s->opaque;
if (!p) return sz ? js_mi_malloc(s, sz) : NULL;
@@ -261,39 +282,68 @@ void *js_mi_realloc(JSMallocState *s, void *p, size_t sz) {
s->malloc_count--;
s->malloc_size -= old_size + MALLOC_OVERHEAD;
#ifdef TRACY_ENABLE
if (tracy_profiling_enabled)
if (tracy_profiling_enabled) {
#ifdef HAVE_MIMALLOC
cell_rt *actor = (cell_rt*)s->opaque;
TracyCFreeN(p, actor->name);
#else
TracyCFreeN(p, "actor");
#endif
}
#endif
#ifdef HAVE_MIMALLOC
mi_free(p);
#else
free(p);
#endif
return NULL;
}
if (s->malloc_size + sz - old_size > s->malloc_limit) return NULL;
#ifdef TRACY_ENABLE
if (tracy_profiling_enabled)
if (tracy_profiling_enabled) {
#ifdef HAVE_MIMALLOC
cell_rt *actor = (cell_rt*)s->opaque;
TracyCFreeN(p, actor->name);
#else
TracyCFreeN(p, "actor");
#endif
}
#endif
#ifdef HAVE_MIMALLOC
cell_rt *actor = (cell_rt*)s->opaque;
p = mi_heap_realloc(actor->heap, p, sz);
#else
p = realloc(p, sz);
#endif
if (!p) return NULL;
s->malloc_size += js_mi_malloc_usable_size(p) - old_size;
#ifdef TRACY_ENABLE
if (tracy_profiling_enabled)
if (tracy_profiling_enabled) {
#ifdef HAVE_MIMALLOC
cell_rt *actor = (cell_rt*)s->opaque;
TracyCAllocN(p, js_mi_malloc_usable_size(p) + MALLOC_OVERHEAD, actor->name);
#else
TracyCAllocN(p, js_mi_malloc_usable_size(p) + MALLOC_OVERHEAD, "actor");
#endif
}
#endif
return p;
}
#ifdef HAVE_MIMALLOC
static const JSMallocFunctions mimalloc_funcs = {
js_mi_malloc,
js_mi_free,
js_mi_realloc,
js_mi_malloc_usable_size
};
#endif
static void free_zip(void)
{
@@ -393,7 +443,9 @@ void actor_unneeded(cell_rt *actor, JSValue fn, double seconds)
cell_rt *create_actor(void *wota)
{
cell_rt *actor = calloc(sizeof(*actor), 1);
#ifdef HAVE_MIMALLOC
actor->heap = mi_heap_new();
#endif
actor->init_wota = wota;
actor->idx_buffer = JS_NULL;
actor->message_handle = JS_NULL;
@@ -739,7 +791,11 @@ void script_startup(cell_rt *prt)
{
JSRuntime *rt;
#ifdef HAVE_MIMALLOC
rt = JS_NewRuntime2(&mimalloc_funcs, prt);
#else
rt = JS_NewRuntime();
#endif
JSContext *js = JS_NewContextRaw(rt);
JS_SetInterruptHandler(rt, actor_interrupt_cb, prt);