-
-
Notifications
You must be signed in to change notification settings - Fork 2
perf(upgrade): use copy-then-mmap for zero JS heap during delta patching #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+465
−38
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ dist-bin | |
|
|
||
| # code coverage | ||
| coverage | ||
| coverage-isolated | ||
| *.lcov | ||
|
|
||
| # test artifacts | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| #!/usr/bin/env bun | ||
| /** | ||
| * Merge multiple LCOV coverage files by taking the MAX hit count per line. | ||
| * | ||
| * The getsentry/codecov-action aggregates multiple coverage files by summing | ||
| * all statements — if a source file appears in two lcov files, its hit counts | ||
| * get doubled rather than merged. This script merges lcov files properly: | ||
| * for each source file, it takes the maximum DA (line hit count) across all | ||
| * input files, producing a single lcov with the best coverage from any suite. | ||
| * | ||
| * All summary fields (LF, LH, FNF, FNH, BRF, BRH) are recomputed from the | ||
| * merged data rather than taking the max from inputs. | ||
| * | ||
| * Usage: bun run script/merge-lcov.ts file1.lcov file2.lcov [file3.lcov ...] | ||
| * Output: merged lcov to stdout | ||
| */ | ||
|
|
||
| export type FileData = { | ||
| /** DA entries: line number → max hit count */ | ||
| da: Map<number, number>; | ||
| /** FN entries: function name → "lineNo,name" */ | ||
| fn: Map<string, string>; | ||
| /** FNDA entries: function name → max execution count */ | ||
| fnda: Map<string, number>; | ||
| /** BRDA entries: "line,block,branch" key → max taken count (string, "-" = not taken) */ | ||
| brda: Map<string, string>; | ||
| /** Max FNF seen from inputs (fallback when no FN/FNDA entries available) */ | ||
| fnfMax: number; | ||
| /** Max FNH seen from inputs (fallback when no FN/FNDA entries available) */ | ||
| fnhMax: number; | ||
| }; | ||
|
|
||
| function createFileData(): FileData { | ||
| return { | ||
| da: new Map(), | ||
| fn: new Map(), | ||
| fnda: new Map(), | ||
| brda: new Map(), | ||
| fnfMax: 0, | ||
| fnhMax: 0, | ||
| }; | ||
| } | ||
|
|
||
| const files = process.argv.slice(2); | ||
| if (files.length === 0) { | ||
| console.error("Usage: merge-lcov.ts <file1.lcov> [file2.lcov ...]"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| /** Merged data per source file path */ | ||
| const merged = new Map<string, FileData>(); | ||
| /** Track insertion order of source files */ | ||
| const fileOrder: string[] = []; | ||
|
|
||
| for (const filePath of files) { | ||
| const content = await Bun.file(filePath).text(); | ||
| let currentSF = ""; | ||
| let data: FileData | null = null; | ||
|
|
||
| for (const line of content.split("\n")) { | ||
| if (line.startsWith("SF:")) { | ||
| currentSF = line.slice(3); | ||
| if (!merged.has(currentSF)) { | ||
| merged.set(currentSF, createFileData()); | ||
| fileOrder.push(currentSF); | ||
| } | ||
| data = merged.get(currentSF) ?? null; | ||
| } else if (line.startsWith("DA:") && data) { | ||
| const comma = line.indexOf(",", 3); | ||
| const lineNo = Number.parseInt(line.slice(3, comma), 10); | ||
| const hits = Number.parseInt(line.slice(comma + 1), 10); | ||
| if (!data.da.has(lineNo) || hits > (data.da.get(lineNo) ?? 0)) { | ||
| data.da.set(lineNo, hits); | ||
| } | ||
| } else if (line.startsWith("FN:") && data) { | ||
| const val = line.slice(3); | ||
| const comma = val.indexOf(","); | ||
| const name = val.slice(comma + 1); | ||
| data.fn.set(name, val); | ||
| } else if (line.startsWith("FNDA:") && data) { | ||
| const val = line.slice(5); | ||
| const comma = val.indexOf(","); | ||
| const count = Number.parseInt(val.slice(0, comma), 10); | ||
| const name = val.slice(comma + 1); | ||
| const prev = data.fnda.get(name) ?? 0; | ||
| if (count > prev) { | ||
| data.fnda.set(name, count); | ||
| } | ||
| } else if (line.startsWith("FNF:") && data) { | ||
| const v = Number.parseInt(line.slice(4), 10); | ||
| if (v > data.fnfMax) { | ||
| data.fnfMax = v; | ||
| } | ||
| } else if (line.startsWith("FNH:") && data) { | ||
| const v = Number.parseInt(line.slice(4), 10); | ||
| if (v > data.fnhMax) { | ||
| data.fnhMax = v; | ||
| } | ||
| } else if (line.startsWith("BRDA:") && data) { | ||
| // BRDA format: line,block,branch,taken | ||
| // Use "line,block,branch" as key, take max of "taken" | ||
| const val = line.slice(5); | ||
| const lastComma = val.lastIndexOf(","); | ||
| const branchKey = val.slice(0, lastComma); | ||
| const taken = val.slice(lastComma + 1); | ||
| const prev = data.brda.get(branchKey); | ||
| if (prev === undefined || prev === "-") { | ||
| // No previous value or previous was "not taken" | ||
| data.brda.set(branchKey, taken); | ||
| } else if (taken !== "-") { | ||
| // Both are numeric — take the max | ||
| const prevNum = Number.parseInt(prev, 10); | ||
| const takenNum = Number.parseInt(taken, 10); | ||
| if (takenNum > prevNum) { | ||
| data.brda.set(branchKey, taken); | ||
| } | ||
| } | ||
| } | ||
| // LF, LH, FNF, FNH, BRF, BRH, end_of_record are all skipped — we recompute them | ||
| } | ||
| } | ||
|
|
||
| // Output merged lcov | ||
| const out: string[] = []; | ||
|
|
||
| for (const sf of fileOrder) { | ||
| const data = merged.get(sf); | ||
| if (!data) { | ||
| continue; | ||
| } | ||
|
|
||
| out.push(`SF:${sf}`); | ||
|
|
||
| // FN lines | ||
| for (const val of data.fn.values()) { | ||
| out.push(`FN:${val}`); | ||
| } | ||
|
|
||
| // FNDA lines + compute FNF/FNH | ||
| let fnh = 0; | ||
| for (const [name, count] of data.fnda) { | ||
| out.push(`FNDA:${count},${name}`); | ||
| if (count > 0) { | ||
| fnh += 1; | ||
| } | ||
| } | ||
|
|
||
| // Prefer recomputed FNF/FNH from merged FN/FNDA entries when available. | ||
| // Bun's lcov output only has FNF/FNH summary lines (no individual FN/FNDA), | ||
| // so fall back to max-of-inputs for those. | ||
| if (data.fn.size > 0) { | ||
| out.push(`FNF:${data.fn.size}`); | ||
| out.push(`FNH:${fnh}`); | ||
| } else if (data.fnfMax > 0) { | ||
| out.push(`FNF:${data.fnfMax}`); | ||
| out.push(`FNH:${data.fnhMax}`); | ||
| } | ||
|
|
||
| // DA lines sorted by line number + compute LF/LH | ||
| const sortedLines = [...data.da.entries()].sort((a, b) => a[0] - b[0]); | ||
| let lh = 0; | ||
| for (const [lineNo, hits] of sortedLines) { | ||
| out.push(`DA:${lineNo},${hits}`); | ||
| if (hits > 0) { | ||
| lh += 1; | ||
| } | ||
| } | ||
| out.push(`LF:${data.da.size}`); | ||
| out.push(`LH:${lh}`); | ||
|
|
||
| // BRDA lines + compute BRF/BRH | ||
| let brh = 0; | ||
| for (const [key, taken] of data.brda) { | ||
| out.push(`BRDA:${key},${taken}`); | ||
| if (taken !== "-" && Number.parseInt(taken, 10) > 0) { | ||
| brh += 1; | ||
| } | ||
| } | ||
| if (data.brda.size > 0) { | ||
| out.push(`BRF:${data.brda.size}`); | ||
| out.push(`BRH:${brh}`); | ||
| } | ||
|
|
||
| out.push("end_of_record"); | ||
| } | ||
|
|
||
| process.stdout.write(`${out.join("\n")}\n`); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.