Skip to content

Micro-optimisations to perform better on JSON and String processing#1280

Merged
saghul merged 2 commits intoquickjs-ng:masterfrom
djinn:master
Dec 31, 2025
Merged

Micro-optimisations to perform better on JSON and String processing#1280
saghul merged 2 commits intoquickjs-ng:masterfrom
djinn:master

Conversation

@djinn
Copy link
Copy Markdown
Contributor

@djinn djinn commented Dec 22, 2025

  • Default string allocation size is set to 48 instead of 32
  • free_token is general Javascript deallocation, json_free_token creates a special case with reduced evaluation for JSON objects

* free_token is general Javascript deallocation, json_free_token creates a special case with reduced evaluation
@bnoordhuis
Copy link
Copy Markdown
Contributor

Can you share some before/after performance numbers? I note there are some unrelated changes in your PR.

@djinn
Copy link
Copy Markdown
Contributor Author

djinn commented Dec 23, 2025

The focus of this is specifically JSON parsing -

Thus I base my work off kraken-1.0/json-parse-financial. I modified the benchmark to run 100x to magnify the impact which is only marginally visible in original.

Screenshot 2025-12-23 at 21 22 36 Screenshot 2025-12-23 at 21 27 20

@djinn
Copy link
Copy Markdown
Contributor Author

djinn commented Dec 23, 2025

The performance data is in "Instruments" format

@djinn
Copy link
Copy Markdown
Contributor Author

djinn commented Dec 23, 2025

I have cleaned up the mix ups with other pieces of code

Copy link
Copy Markdown
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM module some style issues, thanks for the PR!

Comment thread quickjs.c Outdated
Comment on lines +21464 to +21466
if (p >= s->buf_end) {
goto end_of_input;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (p >= s->buf_end) {
goto end_of_input;
}
if (p >= s->buf_end)
goto end_of_input;

Comment thread quickjs.c Outdated
Comment on lines +20350 to +20358
case TOK_NUMBER:
JS_FreeValue(s->ctx, token->u.num.val);
break;
case TOK_STRING:
JS_FreeValue(s->ctx, token->u.str.str);
break;
case TOK_IDENT:
JS_FreeAtom(s->ctx, token->u.ident.atom);
break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case TOK_NUMBER:
JS_FreeValue(s->ctx, token->u.num.val);
break;
case TOK_STRING:
JS_FreeValue(s->ctx, token->u.str.str);
break;
case TOK_IDENT:
JS_FreeAtom(s->ctx, token->u.ident.atom);
break;
case TOK_NUMBER:
JS_FreeValue(s->ctx, token->u.num.val);
break;
case TOK_STRING:
JS_FreeValue(s->ctx, token->u.str.str);
break;
case TOK_IDENT:
JS_FreeAtom(s->ctx, token->u.ident.atom);
break;

Copy link
Copy Markdown
Contributor Author

@djinn djinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated according to convention

Copy link
Copy Markdown
Contributor Author

@djinn djinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected indentation

Copy link
Copy Markdown
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@saghul saghul merged commit fe4a3fe into quickjs-ng:master Dec 31, 2025
122 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants