Skip to content

Commit

Permalink
Use 1 MB as the default stack size
Browse files Browse the repository at this point in the history
In addition:

- Move the WASI override to quickjs.c
- Allow it to be user defined

Ref: #749 (comment)
  • Loading branch information
saghul committed Dec 16, 2024
1 parent 374915a commit beb1b15
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3636,7 +3636,7 @@ static JSValue js_worker_ctor(JSContext *ctx, JSValue new_target,
/* no join at the end */
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
// musl libc gives threads 80 kb stacks, much smaller than
// JS_DEFAULT_STACK_SIZE (256 kb)
// JS_DEFAULT_STACK_SIZE (1 MB)
pthread_attr_setstacksize(&attr, 2 << 20); // 2 MB, glibc default
ret = pthread_create(&tid, &attr, worker_func, args);
pthread_attr_destroy(&attr);
Expand Down
4 changes: 4 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,10 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
#ifdef __ASAN__
rt->stack_size *= 2; // stack frames are bigger under AddressSanitizer
#endif
#ifdef __wasi__
rt->stack_size = 0;
#endif

JS_UpdateStackTop(rt);

rt->current_exception = JS_UNINITIALIZED;
Expand Down
6 changes: 2 additions & 4 deletions quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,8 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
#define JS_PROP_DEFINE_PROPERTY (1 << 18) /* internal use */
#define JS_PROP_REFLECT_DEFINE_PROPERTY (1 << 19) /* internal use */

#if defined(__wasi__)
#define JS_DEFAULT_STACK_SIZE 0
#else
#define JS_DEFAULT_STACK_SIZE (256 * 1024)
#ifndef JS_DEFAULT_STACK_SIZE
#define JS_DEFAULT_STACK_SIZE (1024 * 1024)
#endif

/* JS_Eval() flags */
Expand Down
2 changes: 1 addition & 1 deletion run-test262.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ static JSValue js_evalScript_262(JSContext *ctx, JSValue this_val,
static void start_thread(js_thread_t *thrd, void *(*start)(void *), void *arg)
{
// musl libc gives threads 80 kb stacks, much smaller than
// JS_DEFAULT_STACK_SIZE (256 kb)
// JS_DEFAULT_STACK_SIZE (1 MB)
static const unsigned stacksize = 2 << 20; // 2 MB, glibc default
#ifdef _WIN32
HANDLE h, cp;
Expand Down

0 comments on commit beb1b15

Please sign in to comment.