Skip to content

Commit

Permalink
perf(lsp): Avoid passing struct into op_resolve (denoland#23452)
Browse files Browse the repository at this point in the history
Going through serde_v8 is slow, so just pass the args separately.
`op_resolve` is especially hot, so any speedups are good.
  • Loading branch information
nathanwhit committed Apr 19, 2024
1 parent f4b5eec commit b5ce9cd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
5 changes: 3 additions & 2 deletions cli/lsp/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4058,9 +4058,10 @@ fn op_release(
#[serde]
fn op_resolve(
state: &mut OpState,
#[serde] args: ResolveArgs,
#[string] base: String,
#[serde] specifiers: Vec<String>,
) -> Result<Vec<Option<(String, String)>>, AnyError> {
op_resolve_inner(state, args)
op_resolve_inner(state, ResolveArgs { base, specifiers })
}

#[inline]
Expand Down
17 changes: 9 additions & 8 deletions cli/tsc/99_main_compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ delete Object.prototype.__proto__;
debug(`host.writeFile("${fileName}")`);
}
return ops.op_emit(
{ fileName, data },
data,
fileName,
);
},
getCurrentDirectory() {
Expand Down Expand Up @@ -717,10 +718,10 @@ delete Object.prototype.__proto__;
: arg;
if (fileReference.fileName.startsWith("npm:")) {
/** @type {[string, ts.Extension] | undefined} */
const resolved = ops.op_resolve({
specifiers: [fileReference.fileName],
base: containingFilePath,
})?.[0];
const resolved = ops.op_resolve(
containingFilePath,
[fileReference.fileName],
)?.[0];
if (resolved) {
isCjsCache.maybeAdd(resolved);
return {
Expand Down Expand Up @@ -750,10 +751,10 @@ delete Object.prototype.__proto__;
debug(` specifiers: ${specifiers.join(", ")}`);
}
/** @type {Array<[string, ts.Extension] | undefined>} */
const resolved = ops.op_resolve({
specifiers,
const resolved = ops.op_resolve(
base,
});
specifiers,
);
if (resolved) {
const result = resolved.map((item) => {
if (item) {
Expand Down
15 changes: 10 additions & 5 deletions cli/tsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,13 @@ struct EmitArgs {
file_name: String,
}

#[op2]
fn op_emit(state: &mut OpState, #[serde] args: EmitArgs) -> bool {
op_emit_inner(state, args)
#[op2(fast)]
fn op_emit(
state: &mut OpState,
#[string] data: String,
#[string] file_name: String,
) -> bool {
op_emit_inner(state, EmitArgs { data, file_name })
}

#[inline]
Expand Down Expand Up @@ -590,9 +594,10 @@ pub struct ResolveArgs {
#[serde]
fn op_resolve(
state: &mut OpState,
#[serde] args: ResolveArgs,
#[string] base: String,
#[serde] specifiers: Vec<String>,
) -> Result<Vec<(String, String)>, AnyError> {
op_resolve_inner(state, args)
op_resolve_inner(state, ResolveArgs { base, specifiers })
}

#[inline]
Expand Down

0 comments on commit b5ce9cd

Please sign in to comment.