From 8766fd20d147c224f4bb6029699bb412bf636182 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 19 Sep 2022 05:19:04 +0000 Subject: [PATCH] Replace OPFS VFS xSleep() impl with a more efficient one (no Worker round-trip needed). FossilOrigin-Name: b9773f164878b0a1b7c88cc7a6d1374ea95f64920065e8b2b178a1afffd82fe5 --- ext/wasm/api/sqlite3-api-opfs.js | 27 ++++++++++++++++----------- ext/wasm/sqlite3-opfs-async-proxy.js | 6 ------ manifest | 18 +++++++++--------- manifest.uuid | 2 +- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/ext/wasm/api/sqlite3-api-opfs.js b/ext/wasm/api/sqlite3-api-opfs.js index ede4fb32b1..d6a9dbd22f 100644 --- a/ext/wasm/api/sqlite3-api-opfs.js +++ b/ext/wasm/api/sqlite3-api-opfs.js @@ -255,10 +255,6 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) 'cleanup default VFS wrapper', ()=>(dVfs ? dVfs.dispose() : null), 'cleanup opfsIoMethods', ()=>opfsIoMethods.dispose() ]; - if(dVfs){ - opfsVfs.$xSleep = dVfs.$xSleep; - opfsVfs.$xRandomness = dVfs.$xRandomness; - } /** Pedantic sidebar about opfsVfs.ondispose: the entries in that array are items to clean up when opfsVfs.dispose() is called, but in this @@ -468,6 +464,7 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) warn("OPFS xGetLastError() has nothing sensible to return."); return 0; }, + //xSleep is optionally defined below xOpen: function f(pVfs, zName, pFile, flags, pOutFlags){ if(!f._){ f._ = { @@ -522,6 +519,10 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) }/*xOpen()*/ }/*vfsSyncWrappers*/; + if(dVfs){ + opfsVfs.$xRandomness = dVfs.$xRandomness; + opfsVfs.$xSleep = dVfs.$xSleep; + } if(!opfsVfs.$xRandomness){ /* If the default VFS has no xRandomness(), add a basic JS impl... */ vfsSyncWrappers.xRandomness = function(pVfs, nOut, pOut){ @@ -533,10 +534,12 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) } if(!opfsVfs.$xSleep){ /* If we can inherit an xSleep() impl from the default VFS then - use it, otherwise install one which is certainly less accurate - because it has to go round-trip through the async worker, but - provides the only option for a synchronous sleep() in JS. */ - vfsSyncWrappers.xSleep = (pVfs,ms)=>opRun('xSleep',ms); + assume it's sane and use it, otherwise install a JS-based + one. */ + vfsSyncWrappers.xSleep = function(pVfs,ms){ + Atomics.wait(state.opSABView, state.opIds.xSleep, 0, ms); + return 0; + }; } /* Install the vfs/io_methods into their C-level shared instances... */ @@ -545,7 +548,6 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) inst = installMethod(opfsVfs); for(let k of Object.keys(vfsSyncWrappers)) inst(k, vfsSyncWrappers[k]); - /** Syncronously deletes the given OPFS filesystem entry, ignoring any errors. As this environment has no notion of "current @@ -646,8 +648,11 @@ sqlite3.installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri) let jRead = wasm.cstringToJs(readBuf); log("xRead() got:",jRead); if("sanity"!==jRead) toss("Unexpected xRead() value."); - log("xSleep()ing before close()ing..."); - opRun('xSleep',1000); + if(vfsSyncWrappers.xSleep){ + log("xSleep()ing before close()ing..."); + vfsSyncWrappers.xSleep(opfsVfs.pointer,2000); + log("waking up from xSleep()"); + } rc = ioSyncWrappers.xClose(fid); log("xClose rc =",rc,"opSABView =",state.opSABView); log("Deleting file:",dbFile); diff --git a/ext/wasm/sqlite3-opfs-async-proxy.js b/ext/wasm/sqlite3-opfs-async-proxy.js index 5969962d7a..3ae6af043a 100644 --- a/ext/wasm/sqlite3-opfs-async-proxy.js +++ b/ext/wasm/sqlite3-opfs-async-proxy.js @@ -287,12 +287,6 @@ const vfsAsyncImpls = { } storeAndNotify('xRead',rc); }, - xSleep: async function f(ms){ - log("xSleep(",ms,")"); - await new Promise((resolve)=>{ - setTimeout(()=>resolve(), ms); - }).finally(()=>storeAndNotify('xSleep',0)); - }, xSync: async function({fid,flags/*ignored*/}){ log("xSync(",arguments[0],")"); const fh = __openFiles[fid]; diff --git a/manifest b/manifest index ce729f04c1..5116b71772 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Rename\sdemo-oo1.*\sto\sdemo-123.*\sand\sadd\sdemo-123-worker.html,\swhich\sruns\sthe\ssame\sdemo\svia\sa\sWorker.\sDoc\stypo\sfixes. -D 2022-09-19T03:57:31.704 +C Replace\sOPFS\sVFS\sxSleep()\simpl\swith\sa\smore\sefficient\sone\s(no\sWorker\sround-trip\sneeded). +D 2022-09-19T05:19:04.566 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -484,7 +484,7 @@ F ext/wasm/api/post-js-header.js 0e853b78db83cb1c06b01663549e0e8b4f377f12f5a2d9a F ext/wasm/api/sqlite3-api-cleanup.js 8564a6077cdcaea9a9f428a019af8a05887f0131e6a2a1e72a7ff1145fadfe77 F ext/wasm/api/sqlite3-api-glue.js 366d580c8e5bf7fcf4c6dee6f646c31f5549bd417ea03a59a0acca00e8ecce30 F ext/wasm/api/sqlite3-api-oo1.js 2d13dddf0d2b4168a9249f124134d37924331e5b55e05dba18b6d661fbeefe48 -F ext/wasm/api/sqlite3-api-opfs.js 4090abf4e16b460543ff665e96822048e37a2703e0ba46a01fed3a15c024c034 +F ext/wasm/api/sqlite3-api-opfs.js d44f724990e99e242725c6623d6e1fbf843addabac13aabcd8adc8b7a02cb8b6 F ext/wasm/api/sqlite3-api-prologue.js 4e3e26880d444000cca1b4f3ddfa9d49581dfecd1de9426080239ecc208c447d F ext/wasm/api/sqlite3-api-worker1.js ee4cf149cbacb63d06b536674f822aa5088b7e022cdffc69f1f36cebe2f9fea0 F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9 @@ -497,8 +497,8 @@ F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d695 F ext/wasm/common/testing.css 3a5143699c2b73a85b962271e1a9b3241b30d90e30d895e4f55665e648572962 F ext/wasm/common/whwasmutil.js f7282ef36c9625330d4e6e82d1beec6678cd101e95e7108cd85db587a788c145 F ext/wasm/demo-123-worker.html e419b66495d209b5211ec64903b4cfb3ca7df20d652b41fcd28bf018a773234f -F ext/wasm/demo-123.html aa281d33b7eefa755f3122b7b5a18f39a42dc5fb69c8879171bf14b4c37c4ec4 w ext/wasm/demo-oo1.html -F ext/wasm/demo-123.js 2c5e7775339624819067fd169d202004faeddc9d8ef452dd1f95aa4b3972a5b2 w ext/wasm/demo-oo1.js +F ext/wasm/demo-123.html aa281d33b7eefa755f3122b7b5a18f39a42dc5fb69c8879171bf14b4c37c4ec4 +F ext/wasm/demo-123.js 2c5e7775339624819067fd169d202004faeddc9d8ef452dd1f95aa4b3972a5b2 F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/fiddle/fiddle-worker.js bccf46045be8824752876f3eec01c223be0616ccac184bffd0024cfe7a3262b8 F ext/wasm/fiddle/fiddle.html 550c5aafce40bd218de9bf26192749f69f9b10bc379423ecd2e162bcef885c08 @@ -521,7 +521,7 @@ F ext/wasm/speedtest1.html fbb8e4d1639028443f3687a683be660beca6927920545cf6b1fdf F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0 F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5 -F ext/wasm/sqlite3-opfs-async-proxy.js 6e89e1af7c616afdd877cbcf5d0ec3d5f47ba252b9a19e696140b9495dc1e653 +F ext/wasm/sqlite3-opfs-async-proxy.js 7806909f6957c6173843b53087b7f01fb41fb27f52bdad250fe2081d0fa44f9e F ext/wasm/sqlite3-worker1-promiser.js 4fd0465688a28a75f1d4ee4406540ba494f49844e3cad0670d0437a001943365 F ext/wasm/sqlite3-worker1.js 0c1e7626304543969c3846573e080c082bf43bcaa47e87d416458af84f340a9e F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5 @@ -2028,8 +2028,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9a9eeebc2c27b734041089131b4952d7c0440df48ef32f355641aca61d4b30a0 -R 8192577a9e0361d9ed4a520726bee437 +P 2e4a005bd35424caeaa99ace23162cf79e2ebdb159475ffad92b85dc864ad764 +R 7b4ce0e4c47ddeace77c92f8cdf4ccc9 U stephan -Z 37e4874c91d49fe3eefc7a1b4b57c686 +Z 2dc660cb87f9b9223b60fbf12ba2d753 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 29452e9015..1e0d5dc9cb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2e4a005bd35424caeaa99ace23162cf79e2ebdb159475ffad92b85dc864ad764 \ No newline at end of file +b9773f164878b0a1b7c88cc7a6d1374ea95f64920065e8b2b178a1afffd82fe5 \ No newline at end of file