mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
A modern runtime for JavaScript and TypeScript.
https://deno.com/
f843a1fdff
This PR caches `_iterableHeaders` for immutable `Headers` increasing the performance of `fetch` & server if headers are iterated. Should close #19466 I only cached immutable headers to address this comment https://github.com/denoland/deno/issues/19466#issuecomment-1589892373 since I didn't find any occurrence of header mutation on immutable headers. We can discuss caching for non-immutable, but I think this is a great first step. ## BENCHMARK ### Server ```js const addr = Deno.args[0] ?? "127.0.0.1:4500"; const [hostname, port] = addr.split(":"); const { serve } = Deno; serve({ hostname, port: Number(port), reusePort: true }, (req) => { const headers = [...req.headers]; // req.headers are immutable, cannot set/append/delete return new Response("ok"); }); ``` Used `wrk` with 5 headers ``` wrk -d 10s --latency -H "X-Deno: true" -H "Accept: application/json" -H "X-Foo: bar" -H "User-Agent: wrk" -H "Accept-Encoding: gzip, br" http://127.0.0.1:4500 ``` **This patch** ``` Running 10s test @ http://127.0.0.1:4500 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 70.18us 22.89us 679.00us 81.37% Req/Sec 71.55k 9.69k 82.18k 89.60% Latency Distribution 50% 59.00us 75% 89.00us 90% 98.00us 99% 159.00us 1437891 requests in 10.10s, 193.35MB read Requests/sec: 142369.83 Transfer/sec: 19.14MB ``` **main** ``` Running 10s test @ http://127.0.0.1:4500 2 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 112.78us 36.47us 2.09ms 77.99% Req/Sec 44.30k 1.65k 49.14k 74.26% Latency Distribution 50% 99.00us 75% 136.00us 90% 162.00us 99% 213.00us 890588 requests in 10.10s, 118.91MB read Requests/sec: 88176.37 Transfer/sec: 11.77MB ``` ### fetch ```js const res = await fetch('http://127.0.0.1:4500'); Deno.bench("Headers iterator", () => { const i = [...res.headers]; // res.headers are immutable, cannot set/append/delete }); ``` **this patch** ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.36.1 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ---------------------------------------------------------------------- ----------------------------- Headers iterator 329.5 ns/iter 3,034,909.0 (318.55 ns … 364.34 ns) 331.1 ns 355.72 ns 364.34 ns ``` **main** ``` cpu: 13th Gen Intel(R) Core(TM) i9-13900H runtime: deno 1.36.1 (x86_64-unknown-linux-gnu) benchmark time (avg) iter/s (min … max) p75 p99 p995 ---------------------------------------------------------------------- ----------------------------- Headers iterator 2.59 µs/iter 386,372.1 (2.56 µs … 2.68 µs) 2.59 µs 2.68 µs 2.68 µs ``` |
||
---|---|---|
.cargo | ||
.devcontainer | ||
.github | ||
bench_util | ||
cli | ||
ext | ||
runtime | ||
test_ffi | ||
test_napi | ||
test_util | ||
third_party@7f1a41fee1 | ||
tools | ||
.dlint.json | ||
.dprint.json | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.gitmodules | ||
.rustfmt.toml | ||
Cargo.lock | ||
Cargo.toml | ||
LICENSE.md | ||
README.md | ||
Releases.md | ||
rust-toolchain.toml |
Deno
Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust.
Features
- Secure by default. No file, network, or environment access, unless explicitly enabled.
- Provides
web platform functionality and APIs,
e.g. using ES modules, web workers, and
fetch()
. - Supports TypeScript out of the box.
- Ships only a single executable file.
- Built-in tooling including
deno test
,deno fmt
,deno bench
, and more. - Includes a set of reviewed standard modules guaranteed to work with Deno.
- Supports npm.
Install
Shell (Mac, Linux):
curl -fsSL https://deno.land/install.sh | sh
PowerShell (Windows):
irm https://deno.land/install.ps1 | iex
Homebrew (Mac):
brew install deno
Chocolatey (Windows):
choco install deno
Scoop (Windows):
scoop install deno
Build and install from source using Cargo:
cargo install deno --locked
See deno_install and releases for other options.
Getting Started
deno run https://deno.land/std/examples/welcome.ts
Or setup a simple HTTP server:
Deno.serve((_req) => new Response("Hello, World!"));
Additional Resources
- The Deno Manual is a great starting point for additional examples, setting up your environment, using npm, and more.
- Runtime API reference documents all APIs built into Deno CLI.
- Deno Standard Modules do not have external dependencies and are reviewed by the Deno core team.
- deno.land/x is the registry for third party modules.
- Blog is where the Deno team shares important product updates and “how to”s about solving technical problems.
Contributing
We appreciate your help!
To contribute, please read our contributing instructions.