summaryrefslogtreecommitdiff
path: root/ext/web/lib.rs
AgeCommit message (Collapse)Author
2024-11-08fix: performance.timeOrigin (#26787)snek
`performance.timeOrigin` was being set from when JS started executing, but `op_now` measures from an `std::time::Instant` stored in `OpState`, which is created at a completely different time. This caused `performance.timeOrigin` to be very incorrect. This PR corrects the origin and also cleans up some of the timer code. Compared to `Date.now()`, `performance`'s time origin is now consistently within 5us (0.005ms) of system time. ![image](https://github.com/user-attachments/assets/0a7be04a-4f6d-4816-bd25-38a2e6136926)
2024-10-17refactor(ext/web): use concrete error types (#26185)Leo Kettmeir
2024-08-06fix(ext/web): make TextDecoderResource use cppgc (#24888)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/24878
2024-08-02Revert "perf(ext/node): improve `Buffer` from string performance" (#24851)Luca Casonato
2024-07-30perf(ext/node): improve `Buffer` from string performance (#24567)Divy Srivastava
Fixes https://github.com/denoland/deno/issues/24323 - Use a Buffer pool for `fromString` - Implement fast call base64 writes - Direct from string `create` method for each encoding op ``` $ deno bench -A bench.mjs # 1.45.1+fee4d3a cpu: Apple M1 Pro runtime: deno 1.45.1+fee4d3a (aarch64-apple-darwin) benchmark time (avg) (min … max) p75 p99 p999 ----------------------------------------------------------- ----------------------------- Buffer.from base64 550 ns/iter (490 ns … 1'265 ns) 572 ns 606 ns 1'265 ns Buffer#write base64 285 ns/iter (259 ns … 371 ns) 307 ns 347 ns 360 ns $ ~/gh/deno/target/release/deno bench -A bench.mjs # this PR cpu: Apple M1 Pro runtime: deno dev (aarch64-apple-darwin) benchmark time (avg) (min … max) p75 p99 p999 ----------------------------------------------------------- ----------------------------- Buffer.from base64 151 ns/iter (145 ns … 770 ns) 148 ns 184 ns 648 ns Buffer#write base64 62.58 ns/iter (60.79 ns … 157 ns) 61.65 ns 75.79 ns 141 ns $ node bench.mjs # v22.4.0 cpu: Apple M1 Pro runtime: node v22.4.0 (arm64-darwin) benchmark time (avg) (min … max) p75 p99 p999 ----------------------------------------------------------- ----------------------------- Buffer.from base64 163 ns/iter (96.92 ns … 375 ns) 99.45 ns 127 ns 220 ns Buffer#write base64 75.48 ns/iter (74.97 ns … 134 ns) 75.17 ns 81.83 ns 96.84 ns ```
2024-07-02fix(ext/web): use primordials of ES2024 ArrayBuffer transfer (#24396)Kenta Moriuchi
Ref: https://github.com/denoland/deno_core/issues/135
2024-06-14chore: upgrade to rust 1.79 (#24207)Satya Rohith
2024-03-16fix(ext/node): support MessagePort in `WorkerOptions.workerData` (#22950)Bartek Iwańczuk
This commit fixes passing `MessagePort` instances to `WorkerOptions.workerData`. Before they were not serialized and deserialized properly when spawning a worker thread. Closes https://github.com/denoland/deno/issues/22935
2024-03-11fix(ext/node) implement receiveMessageOnPort for node:worker_threads (#22766)mash-graz
Implementation of `receiveMessageOnPort` for `node:worker_threads` Fixes: #22702
2024-03-01perf(cli): use new deno_core timers (#22569)Matt Mastracci
Improves #19100 Fixes #20356 Replaces #20428 Changes made in deno_core to support this: - [x] Errors must be handled in setTimeout callbacks - [x] Microtask ordering is not-quite-right - [x] Timer cancellation must be checked right before dispatch - [x] Timer sanitizer - [x] Move high-res timer to deno_core - [x] Timers need opcall tracing
2024-02-16chore(ext/web): refactor timer ops before landing op sanitizer (#22435)Matt Mastracci
Splitting the sleep and interval ops allows us to detect an interval timer. We also remove the use of the `op_async_void_deferred` call. A future PR will be able to split the op sanitizer messages for timers and intervals.
2024-02-07chore: upgrade deno_core to 0.259.0 (#22311)Bartek Iwańczuk
This update brings number of ops available to user code down to 45.
2024-02-07refactor: move ImageData to web extension (#22295)Leo Kettmeir
Signed-off-by: Leo Kettmeir <crowlkats@toaxl.com>
2024-01-22feat(web): ImageBitmap (#21898)Leo Kettmeir
2024-01-01chore: update copyright to 2024 (#21753)David Sherret
2023-12-06feat(ext/web): add ImageData Web API (#21183)Jamie
Fixes #19288 Adds the `ImageData` Web API. This would be beneficial to projects using `ImageData` as a convenient transport layer for pixel data. This is common in Web Assembly projects that manipulate images. Having this global available in Deno would improve compatibility of existing JS libraries. **References** - [MDN ImageData Web API](https://developer.mozilla.org/en-US/docs/Web/API/ImageData) - [whatwg HTML Standard Canvas Spec](https://html.spec.whatwg.org/multipage/canvas.html#pixel-manipulation)
2023-12-01refactor: use resourceForReadableStream for fetch (#20217)Matt Mastracci
Switch `ext/fetch` over to `resourceForReadableStream` to simplify and unify implementation with `ext/serve`. This allows us to work in Rust with resources only. Two additional changes made to `resourceForReadableStream` were required: - Add an optional length to `resourceForReadableStream` which translates to `size_hint` - Fix a bug where writing to a closed stream that was full would panic
2023-10-25chore: update deno_core and port all remaining ops to `op2` (#20954)Bartek Iwańczuk
Signed-off-by: Matt Mastracci <matthew@mastracci.com> Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-10-05refactor: rewrite several extension ops to op2 (#20457)Bartek Iwańczuk
Rewrites following extensions: - `ext/web` - `ext/url` - `ext/webstorage` - `ext/io` --------- Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-09-23feat(ext/web): use readableStreamDefaultReaderRead in ↵Matt Mastracci
resourceForReadableStream (#20622) We can go one level down in abstraction and avoid using the public `ReadableStream` APIs. This patch ~5% perf boost on small ReadableStream: ``` Running 10s test @ http://localhost:8080/ 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 148.32us 108.95us 3.88ms 95.71% Req/Sec 33.24k 2.68k 37.94k 73.76% 668188 requests in 10.10s, 77.74MB read Requests/sec: 66162.91 Transfer/sec: 7.70MB ``` main: ``` Running 10s test @ http://localhost:8080/ 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 150.23us 67.61us 4.39ms 94.80% Req/Sec 31.81k 1.55k 35.56k 83.17% 639078 requests in 10.10s, 74.36MB read Requests/sec: 63273.72 Transfer/sec: 7.36MB ```
2023-08-17feat(ext/web): resourceForReadableStream (#20180)Matt Mastracci
Extracted from fast streams work. This is a resource wrapper for `ReadableStream`, allowing us to treat all `ReadableStream` instances as resources, and remove special paths in both `fetch` and `serve`. Performance with a ReadableStream response yields ~18% improvement: ``` return new Response(new ReadableStream({ start(controller) { controller.enqueue(new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])); controller.close(); } }) ``` This patch: ``` 12:36 $ third_party/prebuilt/mac/wrk http://localhost:8080 Running 10s test @ http://localhost:8080 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 99.96us 100.03us 6.65ms 98.84% Req/Sec 47.73k 2.43k 51.02k 89.11% 959308 requests in 10.10s, 117.10MB read Requests/sec: 94978.71 Transfer/sec: 11.59MB ``` main: ``` Running 10s test @ http://localhost:8080 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 163.03us 685.51us 19.73ms 99.27% Req/Sec 39.50k 3.98k 66.11k 95.52% 789582 requests in 10.10s, 82.83MB read Requests/sec: 78182.65 Transfer/sec: 8.20MB ```
2023-07-02Reland "fix(cli): don't store blob and data urls in the module cache" (#18581)Nayeem Rahman
Relands #18261 now that https://github.com/lucacasonato/esbuild_deno_loader/pull/54 is landed and used by fresh. Fixes #18260.
2023-06-22refactor(serde_v8): split ZeroCopyBuf into JsBuffer and ToJsBuffer (#19566)Bartek Iwańczuk
`ZeroCopyBuf` was convenient to use, but sometimes it did hide details that some copies were necessary in certain cases. Also it made it way to easy for the caller to pass around and convert into different values. This commit splits `ZeroCopyBuf` into `JsBuffer` (an array buffer coming from V8) and `ToJsBuffer` (a Rust buffer that will be converted into a V8 array buffer). As a result some magical conversions were removed (they were never used) limiting the API surface and preparing for changes in #19534.
2023-06-06chore: upgrade to Rust 1.70.0 (#19345)David Sherret
Co-authored-by: linbingquan <695601626@qq.com>
2023-05-17feat(ext/web): Request higher-resolution timer on Windows if user requests ↵Matt Mastracci
setTimeout w/short delay (#19149) If a timer is requested with <=100ms resolution, request the high-res timer. Since the default Windows timer period is 15ms, this means a 100ms timer could fire at 115ms (15% late). We assume that timers longer than 100ms are a reasonable cutoff here. The high-res timers on Windows are still limited. Unfortuntely this means that our shortest duration 4ms timers can still be 25% late, but without a more complex timer system or spinning on the clock itself, we're somewhat bounded by the OS' scheduler itself.
2023-05-09fix(core): let V8 drive extension ESM loads (#18997)Luca Casonato
This now allows circular imports across extensions. Instead of load + eval of all ESM files in declaration order, all files are only loaded. Eval is done recursively by V8, only evaluating files that are listed in `Extension::esm_entry_point` fields. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-03-17perf(core) Reduce copying and cloning in extension initialization (#18252)Matt Mastracci
Follow-up to #18210: * we are passing the generated `cfg` object into the state function rather than passing individual config fields * reduce cloning dramatically by making the state_fn `FnOnce` * `take` for `ExtensionBuilder` to avoid more unnecessary copies * renamed `config` to `options`
2023-03-17feat(core) deno_core::extension! macro to simplify extension registration ↵Matt Mastracci
(#18210) This implements two macros to simplify extension registration and centralize a lot of the boilerplate as a base for future improvements: * `deno_core::ops!` registers a block of `#[op]`s, optionally with type parameters, useful for places where we share lists of ops * `deno_core::extension!` is used to register an extension, and creates two methods that can be used at runtime/snapshot generation time: `init_ops` and `init_ops_and_esm`. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-03-09refactor: Split extension registration for runtime and snapshotting (#18095)Bartek Iwańczuk
This commit splits "<ext_name>::init" functions into "init_ops" and "init_ops_and_esm". That way we don't have to construct list of ESM sources on each startup if we're running with a snapshot. In a follow up commit "deno_core" will be changed to not have a split between "extensions" and "extensions_with_js" - it will be embedders' responsibility to pass appropriately configured extensions. Prerequisite for https://github.com/denoland/deno/pull/18080
2023-03-09refactor(core): Extension::builder_with_deps (#18093)Bartek Iwańczuk
Prerequisite for https://github.com/denoland/deno/pull/18080
2023-03-07refactor(core): don't use Result in ExtensionBuilder::state (#18066)Bartek Iwańczuk
There's no point for this API to expect result. If something fails it should result in a panic during build time to signal to embedder that setup is wrong.
2023-03-05feat(ops): relational ops (#18023)Divy Srivastava
Join two independent ops into one. A fast impl of one + a slow callback of another. Here's an example showing optimized paths for latin-1 via fast call and the next-best fallback using V8 apis. ```rust #[op(v8)] fn op_encoding_encode_into_fallback( scope: &mut v8::HandleScope, input: serde_v8::Value, // ... #[op(fast, slow = op_encoding_encode_into_fallback)] fn op_encoding_encode_into( input: Cow<'_, str>, // ... ``` Benchmark results of the fallback path: ``` time target/release/deno run -A --unstable ./cli/tests/testdata/benches/text_encoder_into_perf.js ________________________________________________________ Executed in 70.90 millis fish external usr time 57.76 millis 0.23 millis 57.53 millis sys time 17.02 millis 1.28 millis 15.74 millis target/release/deno_main run -A --unstable ./cli/tests/testdata/benches/text_encoder_into_perf.js ________________________________________________________ Executed in 154.00 millis fish external usr time 67.14 millis 0.26 millis 66.88 millis sys time 38.82 millis 1.47 millis 37.35 millis ```
2023-03-03feat(ops): reland fast zero copy string arguments (#17996)Divy Srivastava
Reland https://github.com/denoland/deno/pull/16777 The codegen is disabled in async ops and when fallback to slow call is possible (return type is a Result) to avoid hitting this V8 bug: https://github.com/denoland/deno/issues/17159
2023-02-07 refactor: remove prefix from include_js_files & use extension name (#17683)Leo Kettmeir
2023-02-07refactor: Use ES modules for internal runtime code (#17648)Leo Kettmeir
This PR refactors all internal js files (except core) to be written as ES modules. `__bootstrap`has been mostly replaced with static imports in form in `internal:[path to file from repo root]`. To specify if files are ESM, an `esm` method has been added to `Extension`, similar to the `js` method. A new ModuleLoader called `InternalModuleLoader` has been added to enable the loading of internal specifiers, which is used in all situations except when a snapshot is only loaded, and not a new one is created from it. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-02-05 refactor: rename `deno` specifiers to `internal` (#17655)Leo Kettmeir
2023-01-27chore: upgrade to Rust 1.67 (#17548)David Sherret
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-01-18chore: upgrade base64-simd to 0.8.0 (#17463)Nugine
This PR upgrades the `base64-simd` dependency of `deno_web`. base64-simd v0.8 supports `forgiving_decode` in ["copy" mode](https://docs.rs/base64-simd/0.8.0/base64_simd/fn.forgiving_decode.html), ["inplace" mode](https://docs.rs/base64-simd/0.8.0/base64_simd/fn.forgiving_decode_inplace.html) or ["alloc" mode](https://docs.rs/base64-simd/0.8.0/base64_simd/fn.forgiving_decode_to_vec.html). When #17159 resolves, they can be used to reduce unnecessary allocations and copies. base64-simd v0.8 also supports AArch64 SIMD out of box.
2023-01-08feat(core): allow specifying name and dependencies of an Extension (#17301)Leo Kettmeir
2023-01-02chore: update copyright year to 2023 (#17247)David Sherret
Yearly tradition of creating extra noise in git.
2022-12-15Revert "feat(ops): Fast zero copy string arguments (#16777)" (#17063)Bartek Iwańczuk
This reverts commit 9b2b8df927ac23cfa99016a684179f2a3198ba2e. Closes https://github.com/dsherret/ts-morph/issues/1372 Closes https://github.com/denoland/deno/issues/16979
2022-12-02feat(ops): Fast zero copy string arguments (#16777)Divy Srivastava
Uses SeqOneByteString optimization to do zero-copy `&str` arguments in fast calls. - [x] Depends on https://github.com/denoland/rusty_v8/pull/1129 - [x] Depends on https://chromium-review.googlesource.com/c/v8/v8/+/4036884 - [x] Disable in async ops - [x] Make it work with owned `String` with an extra alloc in fast path. - [x] Support `Cow<'_, str>`. Owned for slow case, Borrowed for fast case ```rust #[op] fn op_string_len(s: &str) -> u32 { str.len() as u32 } ```
2022-11-30chore: upgrade rusty_v8 to 0.58.0 (#16879)Bartek Iwańczuk
2022-11-12chore: upgrade rusty_v8 to 0.55.0 (#16604)Bartek Iwańczuk
<!-- Before submitting a PR, please read http://deno.land/manual/contributing 1. Give the PR a descriptive title. Examples of good title: - fix(std/http): Fix race condition in server - docs(console): Update docstrings - feat(doc): Handle nested reexports Examples of bad title: - fix #7123 - update docs - fix bugs 2. Ensure there is a related issue and it is referenced in the PR text. 3. Ensure there are tests that cover the changes. 4. Ensure `cargo test` passes. 5. Ensure `./tools/format.js` passes without changing files. 6. Ensure `./tools/lint.js` passes. -->
2022-11-11perf(web): optimize single pass utf8 decoding (#16593)Divy Srivastava
- [x] Avoid copying buffers. https://encoding.spec.whatwg.org/#dom-textdecoder-decode > Implementations are strongly encouraged to use an implementation strategy that avoids this copy. When doing so they will have to make sure that changes to input do not affect future calls to [decode()](https://encoding.spec.whatwg.org/#dom-textdecoder-decode). - [x] Special op to avoid string label deserialization and parsing. (Ideally we should map labels to integers in JS) - [x] Avoid webidl `Object.assign` when options is undefined.
2022-10-26perf(ext/web): optimize transferArrayBuffer (#16294)Divy Srivastava
Avoid copying enqueued data + misc optimizations to skip webidl converter.
2022-10-24perf(ext/web): add op_encode_binary_string (#16352)Marcos Casagrande
Add a new op to use in `reader.readAsBinaryString(blob)`. ``` File API binary string: 400b 35.12 µs/iter (21.93 µs … 3.27 ms) 31.87 µs 131.95 µs 217.63 µs File API binary string: 4kb 46.49 µs/iter (29.36 µs … 4.42 ms) 42.5 µs 122.48 µs 155.1 µs File API binary string: 2.2mb 4.17 ms/iter (1.75 ms … 8.54 ms) 5.48 ms 7.39 ms 8.54 ms ``` **main** ``` benchmark time (avg) (min … max) p75 p99 p995 --------------------------------------------------------------------- ----------------------------- File API binary string: 400b 56.17 µs/iter (43.09 µs … 784.52 µs) 49.6 µs 177.18 µs 241.23 µs File API binary string: 4kb 277.2 µs/iter (240.29 µs … 1.84 ms) 269.87 µs 649.79 µs 774.46 µs File API binary string: 2.2mb 180.03 ms/iter (173.32 ms … 194.35 ms) 182.54 ms 194.35 ms 194.35 ms ``` It can also handle bigger files, when encoding a 200mb file, main crashes with OOM ``` <--- Last few GCs ---> [132677:0x560504676550] 5012 ms: Scavenge 417.3 (434.6) -> 401.8 (434.6) MB, 0.1 / 0.0 ms (average mu = 0.824, current mu = 0.825) allocation failure; [132677:0x560504676550] 5038 ms: Scavenge 417.3 (434.6) -> 401.8 (434.6) MB, 0.1 / 0.0 ms (average mu = 0.824, current mu = 0.825) allocation failure; [132677:0x560504676550] 5064 ms: Scavenge 417.3 (434.6) -> 401.8 (434.6) MB, 0.1 / 0.0 ms (average mu = 0.824, current mu = 0.825) allocation failure; ```
2022-10-17perf(ext/web): optimize `op_cancel_handle` (#16318)Divy Srivastava
Towards #16315
2022-09-17perf(web): optimize encodeInto() (#15922)Divy Srivastava
2022-09-07perf(ops): inline &[u8] arguments and enable fast API (#15731)Divy Srivastava