Skip to content

Commit

Permalink
feat(query-engine-wasm): [analyse] add Wasm sections to "crates" script
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno committed Jan 9, 2024
1 parent f644f4d commit 068233b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion query-engine/query-engine-wasm/analyse/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
- `pnpm i`: Install dependencies.
- `pnpm build`: Build the Wasm binary in `"profiling"` mode.
- `pnpm prepare:crates`: Invoke `twiggy top` on the Wasm binary, saving the results in `./twiggy.profiling.json`.
- `pnpm crates`: Filter and analyse the `twiggy top` results, printing a summary Markdown table of the size impact of each Rust crate involved.
- `pnpm crates`: Filter and analyse the `twiggy top` results, printing a summary Markdown table of the size impact of each Rust crate involved. Wasm sections, like `data` (bunch of static strings) also appear in the table, and are marked with a `🧩`.
36 changes: 26 additions & 10 deletions query-engine/query-engine-wasm/analyse/src/crates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@ type ParsedTwiggyEntry = {
}

function parseEntry({ name, ...rest }: TwiggyEntry): ParsedTwiggyEntry | undefined {
const sections = [
'data',
'type',
'global',
'table',
'elem',
'memory',
]

if (
sections.some(section => name.startsWith(`${section}[`))
) {
let sectionName = name.split('[')[0]
sectionName = `${sectionName}[..] 🧩`

return {
crate: sectionName,
original: {
name,
...rest,
},
}
}

const prefixesToAvoid = [
// exported functions
'queryengine_',
Expand All @@ -22,12 +46,6 @@ function parseEntry({ name, ...rest }: TwiggyEntry): ParsedTwiggyEntry | undefin

// misc. noise
'"function names"',
'data[',
'type[',
'global[',
'table[',
'elem[',
'memory[',
'export ',
'import ',
]
Expand Down Expand Up @@ -59,17 +77,15 @@ function parseEntry({ name, ...rest }: TwiggyEntry): ParsedTwiggyEntry | undefin
name = match ? match[1] : name

// extract the crate name, e.g., `psl_core`
let crateName = name.split('::')[0]
const crateName = name.split('::')[0]

const parsedTwiggyEntry: ParsedTwiggyEntry = {
return {
crate: crateName,
original: {
name,
...rest,
},
}

return parsedTwiggyEntry
}

// print the twiggy data as a markdown table with columns:
Expand Down

0 comments on commit 068233b

Please sign in to comment.