File tree Expand file tree Collapse file tree 6 files changed +388
-29
lines changed
benchmark/sirun/ast-parser Expand file tree Collapse file tree 6 files changed +388
-29
lines changed Original file line number Diff line number Diff line change 2424# TODO: upstream jobs
2525
2626jobs :
27+ ast-bench :
28+ strategy :
29+ # when one version fails, say 14, all the other versions are stopped
30+ # setting fail-fast to false in an attempt to prevent this from happening
31+ fail-fast : false
32+ matrix :
33+ impl : [acorn, orchestrion, oxc, swc]
34+ runs-on : ubuntu-latest
35+ steps :
36+ - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
37+ - uses : ./.github/actions/node/active-lts
38+ - uses : ./.github/actions/install
39+ - run : node -e "console.log('hello')"
40+ - run : time node ${{ matrix.impl }}
41+
2742 bun-pack :
2843 runs-on : ubuntu-latest
2944 steps :
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ /* eslint-disable import/no-extraneous-dependencies */
4+
5+ const {
6+ PARSE ,
7+ USE_ACORN ,
8+ USE_OXC ,
9+ USE_SWC
10+ } = process . env
11+
12+ const code = `
13+ import { useState } from 'react';
14+
15+ function MyComponent() {
16+ const [count, setCount] = useState(0);
17+
18+ const increment = () => {
19+ setCount(count + 1);
20+ };
21+
22+ return 'test';
23+ }
24+ `
25+
26+ if ( USE_ACORN === 'true' ) {
27+ const { parse } = require ( 'acorn' )
28+
29+ if ( PARSE === 'true' ) {
30+ parse ( code )
31+ }
32+ }
33+
34+ if ( USE_OXC === 'true' ) {
35+ const { parseSync } = require ( 'oxc-parser' )
36+
37+ if ( PARSE === 'true' ) {
38+ parseSync ( 'index.js' , code )
39+ }
40+ }
41+
42+ if ( USE_SWC === 'true' ) {
43+ const { parseSync } = require ( '@swc/core' )
44+
45+ if ( PARSE === 'true' ) {
46+ parseSync ( code )
47+ }
48+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " ast-parser" ,
3+ "run" : " node ." ,
4+ "run_with_affinity" : " bash -c \" taskset -c $CPU_AFFINITY node .\" " ,
5+ "setup" : " bash -c \" yarn add --silent acorn oxc-parser @swc/core\" " ,
6+ "cachegrind" : false ,
7+ "instructions" : true ,
8+ "iterations" : 20 ,
9+ "variants" : {
10+ "control" : {},
11+ "acorn-load" : {
12+ "baseline" : " control" ,
13+ "env" : { "USE_ACORN" : " true" }
14+ },
15+ "acorn-load-parse" : {
16+ "baseline" : " control" ,
17+ "env" : { "USE_ACORN" : " true" , "PARSE" : " true" }
18+ },
19+ "oxc-load" : {
20+ "baseline" : " control" ,
21+ "env" : { "USE_OXC" : " true" }
22+ },
23+ "oxc-load-parse" : {
24+ "baseline" : " control" ,
25+ "env" : { "USE_OXC" : " true" , "PARSE" : " true" }
26+ },
27+ "swc-load" : {
28+ "baseline" : " control" ,
29+ "env" : { "USE_SWC" : " true" }
30+ },
31+ "swc-load-parse" : {
32+ "baseline" : " control" ,
33+ "env" : { "USE_SWC" : " true" , "PARSE" : " true" }
34+ }
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const codeTransformer = require ( '@apm-js-collab/code-transformer' )
4+
5+ // The full instrumentation config
6+ const instrumentation = {
7+ // The name of the diagnostics channel
8+ channelName : 'my-channel' ,
9+ // Define the module you'd like to inject tracing channels into
10+ module : {
11+ name : 'my-module' ,
12+ versionRange : '>=1.0.0' ,
13+ filePath : './dist/index.js' ,
14+ } ,
15+ // Define the function you'd like to instrument
16+ // (e.g., match a method named 'foo' that returns a Promise)
17+ functionQuery : {
18+ methodName : 'fetch' ,
19+ kind : 'Async' ,
20+ } ,
21+ }
22+
23+ // Create an InstrumentationMatcher with an array of instrumentation configs
24+ const matcher = codeTransformer . create ( [ instrumentation ] )
25+
26+ // Get a transformer for a specific module
27+ const transformer = matcher . getTransformer (
28+ 'my-module' ,
29+ '1.2.3' ,
30+ './dist/index.js' ,
31+ )
32+
33+ if ( transformer === undefined ) {
34+ throw new Error ( 'No transformer found for module' )
35+ }
36+
37+ // Transform code
38+ const inputCode = 'async function fetch() { return 42; }'
39+
40+ try {
41+ const result = transformer . transform ( inputCode , 'unknown' )
42+ console . log ( result . code )
43+ } catch ( e ) {
44+ console . log ( e )
45+ }
46+
47+ // Both the matcher and transformer should be freed after use!
48+ matcher . free ( )
49+ transformer . free ( )
Original file line number Diff line number Diff line change 121121 " version.js"
122122 ],
123123 "dependencies" : {
124+ "@apm-js-collab/code-transformer" : " ^0.8.2" ,
124125 "@datadog/libdatadog" : " 0.7.0" ,
125126 "@datadog/native-appsec" : " 10.3.0" ,
126127 "@datadog/native-iast-taint-tracking" : " 4.0.0" ,
134135 "@opentelemetry/api-logs" : " <1.0.0" ,
135136 "@opentelemetry/core" : " >=1.14.0 <1.31.0" ,
136137 "@opentelemetry/resources" : " >=1.0.0 <1.10.0" ,
138+ "@swc/core" : " ^1.14.0" ,
139+ "acorn" : " ^8.15.0" ,
137140 "crypto-randomuuid" : " ^1.0.0" ,
138141 "dc-polyfill" : " ^0.1.10" ,
139142 "escape-string-regexp" : " ^5.0.0" ,
148151 "module-details-from-path" : " ^1.0.4" ,
149152 "mutexify" : " ^1.4.0" ,
150153 "opentracing" : " >=0.14.7" ,
154+ "oxc-parser" : " ^0.96.0" ,
151155 "path-to-regexp" : " ^0.1.12" ,
152156 "pprof-format" : " ^2.1.1" ,
153157 "protobufjs" : " ^7.5.3" ,
You can’t perform that action at this time.
0 commit comments