Commit graph

136 commits

Author SHA1 Message Date
Heyang Zhou 92ebf4afe5
feat(ext/kv): key-value store (#18232)
This commit adds unstable "Deno.openKv()" API that allows to open
a key-value database at a specified path.

---------

Co-authored-by: Luca Casonato <hello@lcas.dev>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-03-22 12:13:24 +08:00
Matt Mastracci 0b4770fa7d
perf(core) Reduce script name and script code copies (#18298)
Reduce the number of copies and allocations of script code by carrying
around ownership/reference information from creation time.

As an advantage, this allows us to maintain the identity of `&'static
str`-based scripts and use v8's external 1-byte strings (to avoid
incorrectly passing non-ASCII strings, debug `assert!`s gate all string
reference paths).

Benchmark results:

Perf improvements -- ~0.1 - 0.2ms faster, but should reduce garbage
w/external strings and reduces data copies overall. May also unlock some
more interesting optimizations in the future.

This requires adding some generics to functions, but manual
monomorphization has been applied (outer/inner function) to avoid code
bloat.
2023-03-21 22:33:12 +00:00
Bartek Iwańczuk cd53ab5427
refactor(ext/node): untangle dependencies between js files (#18284)
Moving some code around in `ext/node` is it's a bit better well defined
and makes it possible for others to embed it.

I expect to see no difference in startup perf with this change.
2023-03-20 14:05:13 -04:00
Matt Mastracci 3487fde236
perf(core) Reduce copying and cloning in extension initialization (#18252)
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-17 22:15:27 +00:00
Matt Mastracci e55b448730
feat(core) deno_core::extension! macro to simplify extension registration (#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-17 18:22:15 +00:00
Leo Kettmeir 35196eab27
BREAKING(unstable): remove WebGPU (#18094)
This PR _**temporarily**_ removes WebGPU (which has behind the
`--unstable` flag in Deno), due to performance complications due to its
presence.

It will be brought back in the future; as a point of reference, Chrome
will ship WebGPU to stable on 26/04/2023.

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2023-03-17 00:29:32 +01:00
Bartek Iwańczuk 29c9a5c90d
refactor: reorder op initialization (#18228)
To be able to preserve "Deno.core.ops" we need to ensure that
ops are registered in the same order in various places, otherwise
we will get mismatch in external references ordering.

Prerequisite for https://github.com/denoland/deno/pull/18080
2023-03-16 18:36:53 +01:00
Bartek Iwańczuk 44e67df1cd
fix: Split extension registration and snapshotting (#18098)
This commit partially reverts changes from
https://github.com/denoland/deno/pull/18095.

Turns out I made a mistake that became apparent when working
on removing "RuntimeOptions::extensions_with_js" in a follow up.
2023-03-09 21:09:45 +01:00
Bartek Iwańczuk 8f207c0f3f
refactor: Split extension registration for runtime and snapshotting (#18095)
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-09 14:56:19 +00:00
Bartek Iwańczuk 72fe9bb470
refactor: rename InternalModuleLoader to ExtModuleLoader, use ext: scheme for snapshotted modules (#18041)
This commit renames "deno_core::InternalModuleLoader" to
"ExtModuleLoader" and changes the specifiers used by the 
modules loaded from this loader to "ext:".

"internal:" scheme was really ambiguous and it's more characters than
"ext:", which should result in slightly smaller snapshot size.

Closes https://github.com/denoland/deno/issues/18020
2023-03-08 12:44:54 +01:00
Bartek Iwańczuk d24c6ea27f
refactor(runtime): conditionally register Extension with source files (#18068)
Since we are snapshotting extension source at build time, there's no
need to define list of sources for the extension at runtime.

This commit changes "deno_node" extension by removing "init_polyfill"
function in favor of "init_polyfill_ops_and_esm()" and "init_polyfill_ops()".

The former is used during snapshot and when "deno_runtime" is compiled
with "dont_create_runtime_snapshot" cargo feature flag. The latter is used
when running a worker from an existing snapshot.

This is a start of a bigger refactor to all extensions - thanks to this
change, we don't have to iterate over all defined source files for extension at
runtime, and because of that we don't have to create a filepath for each of the
source files. It's not a big deal, but we are iterating over 300 files on each start,
and concatenating 3 strings before creating a "PathBuf" for ~200 of them.
This is already visible on the startup flamegraphs and should be avoided.
2023-03-08 12:43:26 +01:00
Bartek Iwańczuk b32a6f8ad2
refactor(core): don't use Result in ExtensionBuilder::state (#18066)
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-07 22:37:37 +01:00
Bartek Iwańczuk fe368b72c1
refactor: Add "deno_fs" extension crate (#18040)
This commit factors out APIs related to file system from "runtime/"
to a separate "deno_fs" extension crate.
2023-03-07 18:13:44 +09:00
Bartek Iwańczuk 489cafd5ba
refactor: use v8::String::new_external_onebyte_static where appropriate (#18051) 2023-03-06 16:37:46 +00:00
Bartek Iwańczuk de0d148d93
refactor(runtime): merge "spawn" into "process" (#18022)
This commit merges "runtime/js/40_spawn.js" into
"runtime/js/40_process.js", and "runtime::ops::spawn" 
into "runtime::ops::process".

It makes little sense to have them separated given that we want to
factor out these APIs into a separate extension crate.
2023-03-05 12:19:34 +00:00
Bartek Iwańczuk 7afa3aceb0
refactor(runtime): factor out deno_io extension crate (#18001)
This is a prerequisite to factor out FS ops to a separate crate.
2023-03-05 00:39:48 +00:00
Bartek Iwańczuk 19bb23b60a
refactor(runtime): factor out FsPermissions for fs ops (#18012)
This will help us with moving fs ops to a separate extension crate.
2023-03-05 00:44:59 +01:00
Bartek Iwańczuk 4c6db7aa14
perf(core, runtime): Further improve startup time (#17860)
This commit further improves startup time by:

- no relying on "JsRuntime::execute_script" for runtime bootstrapping,
this is instead done using V8 APIs directly
- registering error classes during the snapshot time, instead of on
startup

Further improvements can be made, mainly around removing 
"core.initializeAsyncOps()" which takes around 2ms.

This commit should result in ~1ms startup time improvement.
2023-02-22 06:25:31 +05:30
Bartek Iwańczuk 914b08fc19
build: add "include_js_files_for_snapshotting" Cargo feature (#17826)
This allows to not include source code into the binary (because
it will already be included in the V8 snapshot).

Nothing changes for the embedders - everything should still build the
same.

This commit brings the binary size from 87Mb to 82Mb on M1.

Alternative to https://github.com/denoland/deno/pull/17820 and
https://github.com/denoland/deno/pull/17653

---------

Co-authored-by: Leo Kettmeir <crowlkats@toaxl.com>
2023-02-20 21:45:34 +01:00
Bartek Iwańczuk d47147fb6a
feat(ext/node): embed std/node into the snapshot (#17724)
This commit moves "deno_std/node" in "ext/node" crate. The code is
transpiled and snapshotted during the build process.

During the first pass a minimal amount of work was done to create the
snapshot, a lot of code in "ext/node" depends on presence of "Deno"
global. This code will be gradually fixed in the follow up PRs to migrate
it to import relevant APIs from "internal:" modules.

Currently the code from snapshot is not used in any way, and all
Node/npm compatibility still uses code from 
"https://deno.land/std/node" (or from the location specified by 
"DENO_NODE_COMPAT_URL"). This will also be handled in a follow 
up PRs.

---------

Co-authored-by: crowlkats <crowlkats@toaxl.com>
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
2023-02-14 17:38:45 +01:00
Bartek Iwańczuk b3c85c3548
feat(node): stabilize Node-API (#17553)
This commit stabilizes Node-API, the "--unstable" flag is no longer
required to load native extensions. "--allow-ffi" permission is still 
required to load them.
2023-02-14 15:53:00 +01:00
Leo Kettmeir 84a96110cd
refactor: rename deno specifiers to internal (#17655) 2023-02-05 17:49:20 +01:00
Divy Srivastava d5634164cb
chore: use rustfmt imports_granularity option (#17421)
Closes https://github.com/denoland/deno/issues/2699
Closes https://github.com/denoland/deno/issues/2347

Uses unstable rustfmt features. Since dprint invokes `rustfmt` we do not
need to switch the cargo toolchain to nightly. Do we care about
formatting stability of our codebase across Rust versions? (I don't)
2023-01-14 23:18:58 -05:00
Leo Kettmeir c41d4ff90e
feat(core): allow specifying name and dependencies of an Extension (#17301) 2023-01-08 23:48:46 +01:00
Bartek Iwańczuk fac6447815
refactor(permissions): add PermissionsContainer struct for internal mutability (#17134)
Turns out we were cloning permissions which after prompting were discarded,
so the state of permissions was never preserved. To handle that we need to store
all permissions behind "Arc<Mutex<>>" (because there are situations where we
need to send them to other thread).

Testing and benching code still uses "Permissions" in most places - it's undesirable
to share the same permission set between various test/bench files - otherwise
granting or revoking permissions in one file would influence behavior of other test
files.
2023-01-07 17:25:34 +01:00
David Sherret 10e4b2e140
chore: update copyright year to 2023 (#17247)
Yearly tradition of creating extra noise in git.
2023-01-02 21:00:42 +00:00
Bartek Iwańczuk fd51b2e506
fix(npm): allow to inspect npm modules with --inspect-brk (#16841) 2022-11-28 21:59:36 +01:00
Leo Kettmeir 9202611e36
fix(runtime): feature-flag snapshot from snapshot (#16843) 2022-11-28 12:47:25 +01:00
Bartek Iwańczuk d232746928
feat(core): Ability to create snapshots from existing snapshots (#16597)
Co-authored-by: crowlkats <crowlkats@toaxl.com>
2022-11-21 14:36:26 +01:00
Bartek Iwańczuk 53e974b276
feat: remove --unstable flag requirement for npm: specifiers (#16473)
This commit makes "npm:" specifiers not require "--unstable" flag.
At the moment some APIs used by Node polyfills still require
"--unstable" which will be addressed in follow up PRs.
2022-11-10 17:57:10 +01:00
Divy Srivastava 851db03a6e
perf(core): do not drive JsInspector by default (#16410)
Part of https://github.com/denoland/deno/pull/16377
2022-10-26 17:07:50 +05:30
Divy Srivastava 0b016a7fb8
feat(npm): implement Node API (#13633)
This PR implements the NAPI for loading native modules into Deno. 

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: DjDeveloper <43033058+DjDeveloperr@users.noreply.github.com>
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
2022-10-05 19:36:44 +05:30
Satya Rohith b312279e58
feat: implement Web Cache API (#15829) 2022-09-28 17:41:12 +05:30
David Sherret 73efed218f
refactor(npm): create general use NpmPackageResolver (#15882) 2022-09-13 11:59:01 -04:00
Bartek Iwańczuk 6bb72a8086
feat(unstable): add more permission checks for ext/node/ (#15581) 2022-08-24 18:07:49 +02:00
David Sherret 87f80ff6be
feat(unstable): initial support for npm specifiers (#15484)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2022-08-20 11:31:33 -04:00
Divy Srivastava cd21cff299
feat(ext/flash): An optimized http/1.1 server (#15405)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Ben Noordhuis <info@bnoordhuis.nl>
Co-authored-by: crowlkats <crowlkats@toaxl.com>
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
2022-08-18 17:35:02 +05:30
David Sherret 868c7e38bf
feat(runtime): add pre_execute_module_cb (#15485) 2022-08-16 21:00:35 -04:00
David Sherret 321a42d1fb
refactor(runtime): split up MainWorker and WebWorker's preload_module method into two separate methods (#15451) 2022-08-10 18:10:51 -04:00
David Sherret 04d402116c
chore: temporarily disable ext/node and use unstable ops (#15438) 2022-08-09 22:09:51 -04:00
Bartek Iwańczuk 1f54d87789
feat: add ext/node for require support (#15362)
This commit adds "ext/node" extension that implementes CommonJS module system.

In the future this extension might be extended to actually contain implementation of
Node compatibility layer in favor of "deno_std/node".

Currently this functionality is not publicly exposed, it is available via "Deno[Deno.internal].require"
namespace and is meant to be used by other functionality to be landed soon.

This is a minimal first pass, things that still don't work:

support for dynamic imports in CJS
conditional exports
2022-08-09 21:06:01 +02:00
cuobiezi 83818c914b
refactor: rename run_basic to run_local (#15068) 2022-07-11 19:02:23 +02:00
Bartek Iwańczuk a919a5dd11
Revert "refactor(snapshots): to their own crate (#14794)" (#15076)
This reverts commit fd5a12d7e2.
2022-07-05 00:12:41 +02:00
Aaron O'Mullan fd5a12d7e2
refactor(snapshots): to their own crate (#14794)
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2022-06-24 15:04:45 +02:00
Bartek Iwańczuk fc3a966a2d
Deno.exit() is an alias to self.close() in worker contexts (#14826)
This commit changes Deno.exit() to be an alias to self.close() in worker contexts,
and the provided exit code becomes is ignored.
2022-06-13 23:53:04 +02:00
Bartek Iwańczuk ba13b8e2a9
refactor: ensure exit code reference is passed to all workers (#14814) 2022-06-08 17:45:38 +02:00
Nayeem Rahman 330c820ae8
BREAKING(unstable): Enable Deno namespace in workers by default (#14581)
This commit removes "WorkerOptions.deno" option as a boolean,
as well as "WorkerOptions.deno.namespace" settings. Starting
with this commit all workers have access to "Deno" namespace
by default.
2022-05-17 22:27:17 +02:00
randomicon00 f82a79ffdb
feat: add userAgent property to Navigator's prototype (#14415) 2022-05-14 12:00:02 +02:00
Nayeem Rahman cb884de2e9
fix(runtime/web_worker): Use biased select when getting module result (#14553) 2022-05-10 11:26:57 +02:00
Nayeem Rahman 9853c96cc4
refactor: Remove PrettyJsError and js_error_create_fn (#14378)
This commit:
- removes "fmt_errors::PrettyJsError" in favor of "format_js_error" fn
- removes "deno_core::JsError::create" and 
"deno_core::RuntimeOptions::js_error_create_fn"
- adds new option to "deno_runtime::ops::worker_host::init"
2022-04-27 01:06:10 +02:00