-
Notifications
You must be signed in to change notification settings - Fork 241
Port some perf improvement commits #1315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
saghul
wants to merge
14
commits into
master
Choose a base branch
from
port-perf
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+3,523
−3,062
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use expand_fast_array and direct array assignment instead of JS_CreateDataPropertyUint32 for better performance when creating arrays from value arrays. Ref: bellard/quickjs@f4951ef
- Made JS_GetGlobalVar and JS_SetGlobalVar inline with fast paths - Removed OP_check_var and OP_put_var_strict opcodes - Simplified optimize_scope_make_global_ref to not use strict mode special code - Simplified bytecode optimizations that referenced removed opcodes - Updated microbench.js to use normal functions instead of eval - Regenerated bytecode for updated opcode indices Note: This removes full compliance with the spec for strict mode variable assignment so that they are as fast as in non strict mode (V8, SpiderMonkey and JavaScriptCore do the same). Ref: bellard/quickjs@2c90110
Add inline fast paths for common property access cases: - For OP_get_field and OP_get_field2: Walk prototype chain directly for non-exotic objects with normal data properties - For OP_put_field: Set property directly for writable data properties Falls back to slow path for exotic objects and special property types. Ref: bellard/quickjs@57f8ec0
Add inline fast paths for OP_post_inc and OP_post_dec when the operand is an integer. Fall back to slow path for overflow cases (INT32_MAX for increment, INT32_MIN for decrement) and non-integer values. Ref: bellard/quickjs@e5de89f
Make string_buffer_putc() an inline function with fast paths for common cases: - Direct write for characters < 0x10000 in wide mode - Surrogate pair handling for characters >= 0x10000 with buffer space - Direct write for 8-bit characters in narrow mode Rename string_buffer_putc_slow to string_buffer_putc16_slow and add new string_buffer_putc_slow for full Unicode handling. Ref: bellard/quickjs@79f3ae2
Replace expensive prototype chain traversal with flag checking. Instead of iterating through prototypes to verify no numeric properties exist, the code now: - Adds std_array_prototype field to JSContext to track whether Array.prototype is "normal" (no small index get/set properties) - Adds is_prototype flag to JSObject to identify prototype objects - Removes has_small_array_index from JSShape (now handled differently) - Sets std_array_prototype = false when Array.prototype or Object.prototype is modified in relevant ways - Uses the flag in JS_SetPropertyValue() and OP_put_array_el for fast path decisions This trades one boolean flag check for iterating multiple prototype objects during common array append operations. Ref: bellard/quickjs@c8a8cf5
Add fast path for OP_get_length that directly accesses the length property without calling JS_GetProperty. This mirrors the optimization already done for OP_get_field and OP_get_field2. When the object has a simple length property (not a getter/setter), the value is retrieved directly by walking the prototype chain. Ref: bellard/quickjs@3e5f2bb
Add fast path for push() on fast arrays that bypasses standard object handling and directly manipulates the array's internal value store. The optimization activates when: - The array is a fast array with standard prototype - The array is extensible - The length property is an integer and writable - The new length doesn't overflow When conditions are met, elements are bulk-inserted directly into the internal values array without property lookup overhead. Ref: bellard/quickjs@9a421b3
Instead of using goto to jump to slow path on int32 overflow, directly convert to float64 inline. This improves instruction cache locality and reduces branching overhead. The change affects: - OP_add: inline float conversion on overflow - OP_add_loc: inline float conversion on overflow - OP_sub: inline float conversion on overflow Ref: bellard/quickjs@3d0cc29
154516f to
8177bd9
Compare
- Rename dbuf_realloc to dbuf_claim with clearer semantics: allocate 'len' more bytes relative to current size instead of absolute size - Add overflow protection in dbuf_claim - Change allocation growth from (size * 3 / 2) to (size + size / 2) with overflow checks - Remove unused dbuf_write function - Update all call sites across quickjs.c, libregexp.c, libunicode.c Ref: bellard/quickjs@0d4cd2d
Optimize destructuring by avoiding the creation of reference objects when there are no 'with' statements in the scope chain (which is always the case in strict mode). This uses depth=0 for direct variable access instead of depth=2 with reference creation. Additional optimizations: - has_with_scope() now skips checking in strict mode (no 'with' allowed) - In non-strict mode, modifying a function name is now ignored (OP_scope_put_var with JS_VAR_FUNCTION_NAME emits OP_drop) Note: This removes full compliance with the spec for lvalue resolution when direct eval is present in compound assignments. V8 and other engines behave the same way. Ref: bellard/quickjs@e015918
39f0d99 to
3f6275f
Compare
Contributor
Author
|
@bnoordhuis This is now ready to review. Not sure how you want to go about it though, it grew quite a bit 😅 |
Replace is_local/is_arg boolean fields in JSClosureVar with a single closure_type enum (JSClosureTypeEnum) that supports 8 distinct types: - JS_CLOSURE_LOCAL: local variable in parent function - JS_CLOSURE_ARG: argument variable in parent function - JS_CLOSURE_REF: closure variable reference in parent function - JS_CLOSURE_GLOBAL_REF: global variable reference - JS_CLOSURE_GLOBAL_DECL: global variable declaration (eval) - JS_CLOSURE_GLOBAL: global variable (eval) - JS_CLOSURE_MODULE_DECL: module variable definition (eval) - JS_CLOSURE_MODULE_IMPORT: module import definition (eval) Ref: bellard/quickjs@a6816be
- Add pre-computed JSShape objects for arguments, mapped_arguments - Use fast_array mode with var_refs for JS_CLASS_MAPPED_ARGUMENTS - Arguments object elements now alias function parameters via JSVarRef - Add js_mapped_arguments_finalizer and js_mapped_arguments_mark - Modify JS_NewObjectFromShape to accept props parameter for initialization - Add js_create_var_ref function for creating detached var_refs - Add var_refs to GC immediately in get_var_ref (instead of at close time) The mapped arguments optimization allows arguments[i] to directly reference function parameters, enabling changes to propagate bidirectionally in non-strict mode functions. Ref: bellard/quickjs@9f11034
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See each individual commit for details.