From c252984cbf5fa512a5f05aa9edef8c9f187ee0ed Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Wed, 24 Jan 2024 12:57:40 -0800 Subject: [PATCH 01/13] Refactor Emval JavaScript implementation to avoid heap allocation. --- src/embind/emval.js | 68 ++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/embind/emval.js b/src/embind/emval.js index 174834aa64a3c..3c9ddbb2055c0 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -12,39 +12,39 @@ /*jslint sub:true*/ /* The symbols 'fromWireType' and 'toWireType' must be accessed via array notation to be closure-safe since craftInvokerFunction crafts functions as strings that can't be closured. */ // -- jshint doesn't understand library syntax, so we need to mark the symbols exposed here -/*global getStringOrSymbol, emval_handles, Emval, __emval_unregister, count_emval_handles, emval_symbols, __emval_decref*/ +/*global getStringOrSymbol, emval_freelist, emval_handles, emval_handles_reserved, Emval, __emval_unregister, count_emval_handles, emval_symbols, __emval_decref*/ /*global emval_addMethodCaller, emval_methodCallers, addToLibrary, global, emval_lookupTypes, makeLegalFunctionName*/ /*global emval_get_global*/ var LibraryEmVal = { - $emval_handles__deps: ['$HandleAllocator'], - $emval_handles: "new HandleAllocator();", + // Stack of handles available for reuse. + $emval_freelist: [], + // Array of alternating pairs (value, refcount). + $emval_handles: [], + // Number of handles reserved for non-use (0) or common values w/o refcount. + $emval_handles_reserved: 5, $emval_symbols: {}, // address -> string - $init_emval__deps: ['$count_emval_handles', '$emval_handles'], + $init_emval__deps: ['$count_emval_handles', '$emval_handles', '$emval_handles_reserved'], $init_emval__postset: 'init_emval();', $init_emval: () => { - // reserve some special values. These never get de-allocated. - // The HandleAllocator takes care of reserving zero. - emval_handles.allocated.push( - {value: undefined}, - {value: null}, - {value: true}, - {value: false}, + // reserve 0 and some special values. These never get de-allocated. + emval_handles.push( + 0, 0, + undefined, 0, + null, 0, + true, 0, + false, 0, ); - Object.assign(emval_handles, /** @lends {emval_handles} */ { reserved: emval_handles.allocated.length }), + #if ASSERTIONS + assert(emval_handles.length / 2 === emval_handles_reserved); + #endif Module['count_emval_handles'] = count_emval_handles; }, - $count_emval_handles__deps: ['$emval_handles'], + $count_emval_handles__deps: ['$emval_freelist', '$emval_handles', '$emval_handles_reserved'], $count_emval_handles: () => { - var count = 0; - for (var i = emval_handles.reserved; i < emval_handles.allocated.length; ++i) { - if (emval_handles.allocated[i] !== undefined) { - ++count; - } - } - return count; + return emval_handles.length / 2 - emval_handles_reserved - emval_freelist.length; }, _emval_register_symbol__deps: ['$emval_symbols', '$readLatin1String'], @@ -61,13 +61,16 @@ var LibraryEmVal = { return symbol; }, - $Emval__deps: ['$emval_handles', '$throwBindingError', '$init_emval'], + $Emval__deps: ['$emval_freelist', '$emval_handles', '$throwBindingError', '$init_emval'], $Emval: { toValue: (handle) => { if (!handle) { throwBindingError('Cannot use deleted val. handle = ' + handle); } - return emval_handles.get(handle).value; + #if ASSERTIONS + assert(handle === 1 || emval_handles[handle * 2] !== undefined, `invalid handle: ${handle}`); + #endif + return emval_handles[handle * 2]; }, toHandle: (value) => { @@ -77,23 +80,30 @@ var LibraryEmVal = { case true: return 3; case false: return 4; default:{ - return emval_handles.allocate({refcount: 1, value: value}); + const handle = emval_freelist.pop() || emval_handles.length / 2; + emval_handles[handle * 2] = value; + emval_handles[handle * 2 + 1] = 1; + return handle; } } } }, - _emval_incref__deps: ['$emval_handles'], + _emval_incref__deps: ['$emval_handles', '$emval_handles_reserved'], _emval_incref: (handle) => { - if (handle > 4) { - emval_handles.get(handle).refcount += 1; + if (handle >= emval_handles_Reserved) { + emval_handles[handle * 2 + 1] += 1; } }, - _emval_decref__deps: ['$emval_handles'], + _emval_decref__deps: ['$emval_freelist', '$emval_handles', '$emval_handles_reserved'], _emval_decref: (handle) => { - if (handle >= emval_handles.reserved && 0 === --emval_handles.get(handle).refcount) { - emval_handles.free(handle); + if (handle >= emval_handles_reserved && 0 === --emval_handles[handle * 2 + 1]).refcount) { + #if ASSERTIONS + assert(emval_handles[handle * 2] !== undefined); + #endif + emval_handles[handle * 2] = undefined; + emval_freelist.push(handle); } }, From d90ee09428b017c84985a1c5e9aaa1b3de725391 Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Wed, 24 Jan 2024 13:14:46 -0800 Subject: [PATCH 02/13] fix syntax errors --- src/embind/emval.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/embind/emval.js b/src/embind/emval.js index 3c9ddbb2055c0..429dd173a525e 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -98,7 +98,7 @@ var LibraryEmVal = { _emval_decref__deps: ['$emval_freelist', '$emval_handles', '$emval_handles_reserved'], _emval_decref: (handle) => { - if (handle >= emval_handles_reserved && 0 === --emval_handles[handle * 2 + 1]).refcount) { + if (handle >= emval_handles_reserved && 0 === --emval_handles[handle * 2 + 1]) { #if ASSERTIONS assert(emval_handles[handle * 2] !== undefined); #endif From 9639b41d8cc4d56dfffd34ca00ca8e0ec2d2fe1e Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Mon, 29 Jan 2024 10:52:52 -0800 Subject: [PATCH 03/13] fix typo --- src/embind/emval.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/embind/emval.js b/src/embind/emval.js index 429dd173a525e..09417a3184877 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -91,7 +91,7 @@ var LibraryEmVal = { _emval_incref__deps: ['$emval_handles', '$emval_handles_reserved'], _emval_incref: (handle) => { - if (handle >= emval_handles_Reserved) { + if (handle >= emval_handles_reserved) { emval_handles[handle * 2 + 1] += 1; } }, From 9752e50521fe2474c2d58075dea8fc34d357d5dc Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Tue, 30 Jan 2024 12:49:39 -0800 Subject: [PATCH 04/13] Updates from code review. --- src/embind/emval.js | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/embind/emval.js b/src/embind/emval.js index 09417a3184877..26bcb60f1a2a2 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -12,39 +12,42 @@ /*jslint sub:true*/ /* The symbols 'fromWireType' and 'toWireType' must be accessed via array notation to be closure-safe since craftInvokerFunction crafts functions as strings that can't be closured. */ // -- jshint doesn't understand library syntax, so we need to mark the symbols exposed here -/*global getStringOrSymbol, emval_freelist, emval_handles, emval_handles_reserved, Emval, __emval_unregister, count_emval_handles, emval_symbols, __emval_decref*/ +/*global getStringOrSymbol, emval_freelist, emval_handles, Emval, __emval_unregister, count_emval_handles, emval_symbols, __emval_decref*/ /*global emval_addMethodCaller, emval_methodCallers, addToLibrary, global, emval_lookupTypes, makeLegalFunctionName*/ /*global emval_get_global*/ +// Number of handles reserved for non-use (0) or common values w/o refcount. +{{{ + globalThis.EMVAL_RESERVED_HANDLES = 5; + null; +}}} var LibraryEmVal = { // Stack of handles available for reuse. $emval_freelist: [], // Array of alternating pairs (value, refcount). $emval_handles: [], - // Number of handles reserved for non-use (0) or common values w/o refcount. - $emval_handles_reserved: 5, $emval_symbols: {}, // address -> string - $init_emval__deps: ['$count_emval_handles', '$emval_handles', '$emval_handles_reserved'], + $init_emval__deps: ['$count_emval_handles', '$emval_handles'], $init_emval__postset: 'init_emval();', $init_emval: () => { // reserve 0 and some special values. These never get de-allocated. emval_handles.push( - 0, 0, - undefined, 0, - null, 0, - true, 0, - false, 0, + 0, 1, + undefined, 1, + null, 1, + true, 1, + false, 1, ); #if ASSERTIONS - assert(emval_handles.length / 2 === emval_handles_reserved); + assert(emval_handles.length / 2 === {{{ EMVAL_RESERVED_HANDLES }}}); #endif Module['count_emval_handles'] = count_emval_handles; }, - $count_emval_handles__deps: ['$emval_freelist', '$emval_handles', '$emval_handles_reserved'], + $count_emval_handles__deps: ['$emval_freelist', '$emval_handles'], $count_emval_handles: () => { - return emval_handles.length / 2 - emval_handles_reserved - emval_freelist.length; + return emval_handles.length / 2 - {{{ EMVAL_RESERVED_HANDLES }}}- emval_freelist.length; }, _emval_register_symbol__deps: ['$emval_symbols', '$readLatin1String'], @@ -68,6 +71,7 @@ var LibraryEmVal = { throwBindingError('Cannot use deleted val. handle = ' + handle); } #if ASSERTIONS + // handle 1 is supposed to be `undefined`. assert(handle === 1 || emval_handles[handle * 2] !== undefined, `invalid handle: ${handle}`); #endif return emval_handles[handle * 2]; @@ -89,17 +93,16 @@ var LibraryEmVal = { } }, - _emval_incref__deps: ['$emval_handles', '$emval_handles_reserved'], + _emval_incref__deps: ['$emval_handles'], _emval_incref: (handle) => { - if (handle >= emval_handles_reserved) { - emval_handles[handle * 2 + 1] += 1; - } + emval_handles[handle * 2 + 1] += 1; }, - _emval_decref__deps: ['$emval_freelist', '$emval_handles', '$emval_handles_reserved'], + _emval_decref__deps: ['$emval_freelist', '$emval_handles'], _emval_decref: (handle) => { - if (handle >= emval_handles_reserved && 0 === --emval_handles[handle * 2 + 1]) { + if (0 === --emval_handles[handle * 2 + 1]) { #if ASSERTIONS + assert(handle >= {{{ EMVAL_RESERVED_HANDLES }}}); assert(emval_handles[handle * 2] !== undefined); #endif emval_handles[handle * 2] = undefined; From 889193c18e9d397d324b959f072cb723aba4cd79 Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Tue, 30 Jan 2024 12:58:00 -0800 Subject: [PATCH 05/13] Rebaseline test_minimal_runtime_code_size_hello_embind_val. --- test/code_size/embind_val_wasm.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/code_size/embind_val_wasm.json b/test/code_size/embind_val_wasm.json index 77462a448e15a..99b4dbd81fe13 100644 --- a/test/code_size/embind_val_wasm.json +++ b/test/code_size/embind_val_wasm.json @@ -1,10 +1,10 @@ { "a.html": 673, "a.html.gz": 431, - "a.js": 7411, - "a.js.gz": 3140, - "a.wasm": 11433, - "a.wasm.gz": 5725, - "total": 19517, - "total_gz": 9296 + "a.js": 7178, + "a.js.gz": 3052, + "a.wasm": 11439, + "a.wasm.gz": 5729, + "total": 19290, + "total_gz": 9212 } From fdc625ffff5d956bce93e2d716110ce217d900a7 Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Tue, 30 Jan 2024 13:03:44 -0800 Subject: [PATCH 06/13] Rebaseline test_minimal_runtime_code_size_hello_embind_val. --- test/code_size/embind_val_wasm.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/code_size/embind_val_wasm.json b/test/code_size/embind_val_wasm.json index 99b4dbd81fe13..74e94e06eff60 100644 --- a/test/code_size/embind_val_wasm.json +++ b/test/code_size/embind_val_wasm.json @@ -1,10 +1,10 @@ { "a.html": 673, "a.html.gz": 431, - "a.js": 7178, - "a.js.gz": 3052, - "a.wasm": 11439, - "a.wasm.gz": 5729, - "total": 19290, - "total_gz": 9212 + "a.js": 7155, + "a.js.gz": 3022, + "a.wasm": 11433, + "a.wasm.gz": 5725, + "total": 19261, + "total_gz": 9178 } From 3c2e5e6bc2ff30429af1172c6c78e86427481f14 Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Tue, 30 Jan 2024 14:19:42 -0800 Subject: [PATCH 07/13] Fix test_embind_val --- src/embind/emval.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/embind/emval.js b/src/embind/emval.js index 26bcb60f1a2a2..390722e58c7f6 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -19,6 +19,7 @@ // Number of handles reserved for non-use (0) or common values w/o refcount. {{{ globalThis.EMVAL_RESERVED_HANDLES = 5; + globalThis.EMVAL_LAST_RESERVED_HANDLE = globalThis.EMVAL_RESERVED_HANDLES - 1; null; }}} var LibraryEmVal = { @@ -95,15 +96,16 @@ var LibraryEmVal = { _emval_incref__deps: ['$emval_handles'], _emval_incref: (handle) => { - emval_handles[handle * 2 + 1] += 1; + if (handle > {{{ EMVAL_LAST_RESERVED_HANDLE }}}) { + emval_handles[handle * 2 + 1] += 1; + } }, _emval_decref__deps: ['$emval_freelist', '$emval_handles'], _emval_decref: (handle) => { - if (0 === --emval_handles[handle * 2 + 1]) { + if (handle > {{{ EMVAL_LAST_RESERVED_HANDLE }}} && 0 === --emval_handles[handle * 2 + 1]) { #if ASSERTIONS - assert(handle >= {{{ EMVAL_RESERVED_HANDLES }}}); - assert(emval_handles[handle * 2] !== undefined); + assert(emval_handles[handle * 2] !== undefined, `Decref for unallocated handle.`); #endif emval_handles[handle * 2] = undefined; emval_freelist.push(handle); From 237bd2f3b7f8ff501e9168b50478efbde061abe3 Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Tue, 30 Jan 2024 14:20:29 -0800 Subject: [PATCH 08/13] Rebaseline test_minimal_runtime_code_size_hello_embind_val. --- test/code_size/embind_val_wasm.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/code_size/embind_val_wasm.json b/test/code_size/embind_val_wasm.json index 74e94e06eff60..702b778c9c15b 100644 --- a/test/code_size/embind_val_wasm.json +++ b/test/code_size/embind_val_wasm.json @@ -1,10 +1,10 @@ { "a.html": 673, "a.html.gz": 431, - "a.js": 7155, - "a.js.gz": 3022, + "a.js": 7160, + "a.js.gz": 3027, "a.wasm": 11433, "a.wasm.gz": 5725, - "total": 19261, - "total_gz": 9178 + "total": 19266, + "total_gz": 9183 } From ece8ec58c3a0352e9e2df51751f8acad5445ac5e Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Tue, 30 Jan 2024 14:30:18 -0800 Subject: [PATCH 09/13] Fix formating --- src/embind/emval.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/embind/emval.js b/src/embind/emval.js index 390722e58c7f6..a86bcee280b6d 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -48,7 +48,7 @@ var LibraryEmVal = { $count_emval_handles__deps: ['$emval_freelist', '$emval_handles'], $count_emval_handles: () => { - return emval_handles.length / 2 - {{{ EMVAL_RESERVED_HANDLES }}}- emval_freelist.length; + return emval_handles.length / 2 - {{{ EMVAL_RESERVED_HANDLES }}} - emval_freelist.length; }, _emval_register_symbol__deps: ['$emval_symbols', '$readLatin1String'], From d823c3e11bb0187f1870b56fe2da20a96ee058d4 Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Mon, 5 Feb 2024 12:25:13 -0800 Subject: [PATCH 10/13] Rebaseline test_minimal_runtime_code_size_hello_embind_val. --- test/code_size/embind_val_wasm.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/code_size/embind_val_wasm.json b/test/code_size/embind_val_wasm.json index fe8049be2eb2e..d95d1d4511a82 100644 --- a/test/code_size/embind_val_wasm.json +++ b/test/code_size/embind_val_wasm.json @@ -1,10 +1,10 @@ { "a.html": 673, "a.html.gz": 431, - "a.js": 7325, - "a.js.gz": 3088, + "a.js": 7098, + "a.js.gz": 3001, "a.wasm": 11433, "a.wasm.gz": 5725, - "total": 19431, - "total_gz": 9244 + "total": 19204, + "total_gz": 9157 } From 5e2f3bd5e05fd249463856059aff2f46e5979de3 Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Wed, 7 Feb 2024 11:33:30 -0800 Subject: [PATCH 11/13] Simplify handle code paths even if it means halving the address space. --- src/embind/emval.js | 34 ++++++++++++++--------------- system/include/emscripten/val.h | 8 +++---- test/code_size/embind_val_wasm.json | 8 +++---- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/embind/emval.js b/src/embind/emval.js index a86bcee280b6d..0f03cba8a7db7 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -18,7 +18,7 @@ // Number of handles reserved for non-use (0) or common values w/o refcount. {{{ - globalThis.EMVAL_RESERVED_HANDLES = 5; + globalThis.EMVAL_RESERVED_HANDLES = 10; globalThis.EMVAL_LAST_RESERVED_HANDLE = globalThis.EMVAL_RESERVED_HANDLES - 1; null; }}} @@ -41,14 +41,14 @@ var LibraryEmVal = { false, 1, ); #if ASSERTIONS - assert(emval_handles.length / 2 === {{{ EMVAL_RESERVED_HANDLES }}}); + assert(emval_handles.length === {{{ EMVAL_RESERVED_HANDLES }}}); #endif Module['count_emval_handles'] = count_emval_handles; }, $count_emval_handles__deps: ['$emval_freelist', '$emval_handles'], $count_emval_handles: () => { - return emval_handles.length / 2 - {{{ EMVAL_RESERVED_HANDLES }}} - emval_freelist.length; + return (emval_handles.length - {{{ EMVAL_RESERVED_HANDLES }}}) / 2 - emval_freelist.length; }, _emval_register_symbol__deps: ['$emval_symbols', '$readLatin1String'], @@ -72,22 +72,22 @@ var LibraryEmVal = { throwBindingError('Cannot use deleted val. handle = ' + handle); } #if ASSERTIONS - // handle 1 is supposed to be `undefined`. - assert(handle === 1 || emval_handles[handle * 2] !== undefined, `invalid handle: ${handle}`); + // handle 2 is supposed to be `undefined`. + assert(handle === 2 || emval_handles[handle] !== undefined, `invalid handle: ${handle}`); #endif - return emval_handles[handle * 2]; + return emval_handles[handle]; }, toHandle: (value) => { switch (value) { - case undefined: return 1; - case null: return 2; - case true: return 3; - case false: return 4; + case undefined: return 2; + case null: return 4; + case true: return 6; + case false: return 8; default:{ - const handle = emval_freelist.pop() || emval_handles.length / 2; - emval_handles[handle * 2] = value; - emval_handles[handle * 2 + 1] = 1; + const handle = emval_freelist.pop() || emval_handles.length; + emval_handles[handle] = value; + emval_handles[handle + 1] = 1; return handle; } } @@ -97,17 +97,17 @@ var LibraryEmVal = { _emval_incref__deps: ['$emval_handles'], _emval_incref: (handle) => { if (handle > {{{ EMVAL_LAST_RESERVED_HANDLE }}}) { - emval_handles[handle * 2 + 1] += 1; + emval_handles[handle + 1] += 1; } }, _emval_decref__deps: ['$emval_freelist', '$emval_handles'], _emval_decref: (handle) => { - if (handle > {{{ EMVAL_LAST_RESERVED_HANDLE }}} && 0 === --emval_handles[handle * 2 + 1]) { + if (handle > {{{ EMVAL_LAST_RESERVED_HANDLE }}} && 0 === --emval_handles[handle + 1]) { #if ASSERTIONS - assert(emval_handles[handle * 2] !== undefined, `Decref for unallocated handle.`); + assert(emval_handles[handle] !== undefined, `Decref for unallocated handle.`); #endif - emval_handles[handle * 2] = undefined; + emval_handles[handle] = undefined; emval_freelist.push(handle); } }, diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index 83efee02cb99e..81e7c0d2e88f2 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -46,10 +46,10 @@ extern "C" { void _emval_register_symbol(const char*); enum { - _EMVAL_UNDEFINED = 1, - _EMVAL_NULL = 2, - _EMVAL_TRUE = 3, - _EMVAL_FALSE = 4 + _EMVAL_UNDEFINED = 2, + _EMVAL_NULL = 4, + _EMVAL_TRUE = 6, + _EMVAL_FALSE = 8 }; typedef struct _EM_DESTRUCTORS* EM_DESTRUCTORS; diff --git a/test/code_size/embind_val_wasm.json b/test/code_size/embind_val_wasm.json index d95d1d4511a82..ce9d73f675655 100644 --- a/test/code_size/embind_val_wasm.json +++ b/test/code_size/embind_val_wasm.json @@ -1,10 +1,10 @@ { "a.html": 673, "a.html.gz": 431, - "a.js": 7098, - "a.js.gz": 3001, + "a.js": 7089, + "a.js.gz": 3002, "a.wasm": 11433, "a.wasm.gz": 5725, - "total": 19204, - "total_gz": 9157 + "total": 19195, + "total_gz": 9158 } From b06380fddcff7843e30d7653c3c2a4c00b7d5a4f Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Wed, 7 Feb 2024 11:37:22 -0800 Subject: [PATCH 12/13] Assert that handles are even when validating. --- src/embind/emval.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/embind/emval.js b/src/embind/emval.js index 0f03cba8a7db7..d5f08bf45c2dc 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -73,7 +73,7 @@ var LibraryEmVal = { } #if ASSERTIONS // handle 2 is supposed to be `undefined`. - assert(handle === 2 || emval_handles[handle] !== undefined, `invalid handle: ${handle}`); + assert(handle === 2 || emval_handles[handle] !== undefined && handle % 2 === 0, `invalid handle: ${handle}`); #endif return emval_handles[handle]; }, From a6586c13378e766f6055e31dab3bf6fdc14df69d Mon Sep 17 00:00:00 2001 From: Mike Rolig Date: Wed, 7 Feb 2024 16:49:56 -0800 Subject: [PATCH 13/13] Keep EMVAL_RESERVED_HANDLES as 5 for clarity. --- src/embind/emval.js | 8 ++++---- test/code_size/embind_val_wasm.json | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/embind/emval.js b/src/embind/emval.js index cb0113149b748..8d22ae24839ad 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -18,8 +18,8 @@ // Number of handles reserved for non-use (0) or common values w/o refcount. {{{ - globalThis.EMVAL_RESERVED_HANDLES = 10; - globalThis.EMVAL_LAST_RESERVED_HANDLE = globalThis.EMVAL_RESERVED_HANDLES - 1; + globalThis.EMVAL_RESERVED_HANDLES = 5; + globalThis.EMVAL_LAST_RESERVED_HANDLE = globalThis.EMVAL_RESERVED_HANDLES * 2 - 1; null; }}} var LibraryEmVal = { @@ -41,14 +41,14 @@ var LibraryEmVal = { false, 1, ); #if ASSERTIONS - assert(emval_handles.length === {{{ EMVAL_RESERVED_HANDLES }}}); + assert(emval_handles.length === {{{ EMVAL_RESERVED_HANDLES }}} * 2); #endif Module['count_emval_handles'] = count_emval_handles; }, $count_emval_handles__deps: ['$emval_freelist', '$emval_handles'], $count_emval_handles: () => { - return (emval_handles.length - {{{ EMVAL_RESERVED_HANDLES }}}) / 2 - emval_freelist.length; + return emval_handles.length / 2 - {{{ EMVAL_RESERVED_HANDLES }}} - emval_freelist.length; }, _emval_register_symbol__deps: ['$emval_symbols', '$readLatin1String'], diff --git a/test/code_size/embind_val_wasm.json b/test/code_size/embind_val_wasm.json index ce9d73f675655..a199731962377 100644 --- a/test/code_size/embind_val_wasm.json +++ b/test/code_size/embind_val_wasm.json @@ -1,10 +1,10 @@ { "a.html": 673, "a.html.gz": 431, - "a.js": 7089, - "a.js.gz": 3002, + "a.js": 7086, + "a.js.gz": 3000, "a.wasm": 11433, "a.wasm.gz": 5725, - "total": 19195, - "total_gz": 9158 + "total": 19192, + "total_gz": 9156 }