mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Add ability to compile the CLI with mimalloc
Some (unscientific) benchmark results: | Benchmark (Higher scores are better) | QuickJS | QuickJS (mimalloc) | |---------------------------------------|-------------------|--------------------| | Richards | 1217 | 1229 | | DeltaBlue | 1192 | 1297 | | Crypto | 1195 | 1191 | | RayTrace | 1477 | 2186 | | EarleyBoyer | 2441 | 3246 | | RegExp | 275 | 315 | | Splay | 2461 | 3765 | | NavierStokes | 2156 | 2119 | | Score | 1318 | 1553 | Running the V8 benchmark suite (version 7) on an M1 MacBook Pro. Fixes: https://github.com/quickjs-ng/quickjs/issues/142
This commit is contained in:
parent
cfeeff91db
commit
6ce2dcc938
2 changed files with 46 additions and 2 deletions
|
@ -111,6 +111,7 @@ endif()
|
|||
|
||||
xoption(BUILD_EXAMPLES "Build examples" OFF)
|
||||
xoption(BUILD_STATIC_QJS_EXE "Build a static qjs executable" OFF)
|
||||
xoption(BUILD_CLI_WITH_MIMALLOC "Build the qjs executable with mimalloc" OFF)
|
||||
xoption(CONFIG_ASAN "Enable AddressSanitizer (ASan)" OFF)
|
||||
xoption(CONFIG_MSAN "Enable MemorySanitizer (MSan)" OFF)
|
||||
xoption(CONFIG_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)
|
||||
|
@ -254,7 +255,11 @@ endif()
|
|||
if(NOT WIN32)
|
||||
set_target_properties(qjs_exe PROPERTIES ENABLE_EXPORTS TRUE)
|
||||
endif()
|
||||
|
||||
if(BUILD_CLI_WITH_MIMALLOC)
|
||||
find_package(mimalloc REQUIRED)
|
||||
target_compile_definitions(qjs_exe PRIVATE QJS_USE_MIMALLOC)
|
||||
target_link_libraries(qjs_exe mimalloc-static)
|
||||
endif()
|
||||
|
||||
# Test262 runner
|
||||
#
|
||||
|
|
41
qjs.c
41
qjs.c
|
@ -38,6 +38,10 @@
|
|||
#include "cutils.h"
|
||||
#include "quickjs-libc.h"
|
||||
|
||||
#ifdef QJS_USE_MIMALLOC
|
||||
#include <mimalloc.h>
|
||||
#endif
|
||||
|
||||
extern const uint8_t qjsc_repl[];
|
||||
extern const uint32_t qjsc_repl_size;
|
||||
|
||||
|
@ -230,7 +234,6 @@ static void *js_trace_calloc(void *opaque, size_t count, size_t size)
|
|||
|
||||
static void *js_trace_malloc(void *opaque, size_t size)
|
||||
{
|
||||
(void) opaque;
|
||||
void *ptr;
|
||||
ptr = malloc(size);
|
||||
js_trace_malloc_printf(opaque, "A %zd -> %p\n", size, ptr);
|
||||
|
@ -261,6 +264,38 @@ static const JSMallocFunctions trace_mf = {
|
|||
js__malloc_usable_size
|
||||
};
|
||||
|
||||
#ifdef QJS_USE_MIMALLOC
|
||||
static void *js_mi_calloc(void *opaque, size_t count, size_t size)
|
||||
{
|
||||
return mi_calloc(count, size);
|
||||
}
|
||||
|
||||
static void *js_mi_malloc(void *opaque, size_t size)
|
||||
{
|
||||
return mi_malloc(size);
|
||||
}
|
||||
|
||||
static void js_mi_free(void *opaque, void *ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return;
|
||||
mi_free(ptr);
|
||||
}
|
||||
|
||||
static void *js_mi_realloc(void *opaque, void *ptr, size_t size)
|
||||
{
|
||||
return mi_realloc(ptr, size);
|
||||
}
|
||||
|
||||
static const JSMallocFunctions mi_mf = {
|
||||
js_mi_calloc,
|
||||
js_mi_malloc,
|
||||
js_mi_free,
|
||||
js_mi_realloc,
|
||||
mi_malloc_usable_size
|
||||
};
|
||||
#endif
|
||||
|
||||
#define PROG_NAME "qjs"
|
||||
|
||||
void help(void)
|
||||
|
@ -438,7 +473,11 @@ int main(int argc, char **argv)
|
|||
js_trace_malloc_init(&trace_data);
|
||||
rt = JS_NewRuntime2(&trace_mf, &trace_data);
|
||||
} else {
|
||||
#ifdef QJS_USE_MIMALLOC
|
||||
rt = JS_NewRuntime2(&mi_mf, NULL);
|
||||
#else
|
||||
rt = JS_NewRuntime();
|
||||
#endif
|
||||
}
|
||||
if (!rt) {
|
||||
fprintf(stderr, "qjs: cannot allocate JS runtime\n");
|
||||
|
|
Loading…
Reference in a new issue