You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/guide/api-usage/performance-tip.md
+17-8Lines changed: 17 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,11 +9,13 @@ There are a lot of tricks to improve performance when using `napi`. The mantra i
9
9
`parseAsync` can take advantage of NodeJs' libuv thread pool to parse code in parallel threads. This can be faster than the sync version `parse` when handling a lot of code.
If you have a lot of files to parse and want to maximize your programs' performance, ast-grep's language object provides a `findInFiles` function that parses multiple files and searches relevant nodes in parallel Rust threads.
60
+
If you have a lot of files to parse and want to maximize your programs' performance, ast-grep provides a `findInFiles` function that parses multiple files and searches relevant nodes in parallel Rust threads.
59
61
60
62
APIs we showed above all require parsing code in Rust and pass the `SgRoot` back to JavaScript.
61
63
This incurs foreign function communication overhead and only utilizes the single main JavaScript thread.
@@ -66,6 +68,8 @@ The function signature of `findInFiles` is as follows:
66
68
67
69
```ts
68
70
exportfunction findInFiles(
71
+
/** the language to parse */
72
+
lang:Lang,
69
73
/** specify the file path and matcher */
70
74
config:FindConfig,
71
75
/** callback function for found nodes in a file */
@@ -137,14 +141,19 @@ function countedPromise<F extends Callback>(func: F) {
137
141
Exampleofusing`findInFiles`
138
142
139
143
```ts
140
-
let fileCount = await js.findInFiles({
144
+
import { Lang, findInFiles } from '@ast-grep/napi'
145
+
146
+
let fileCount = await findInFiles(Lang.JavaScript, {
0 commit comments