Skip to content

Commit 72db247

Browse files
committed
fix(perf): print the generated fixture's size on disk
With zstd-compressed Codex rollouts the generator's `Size` line showed the uncompressed bytes, about four times what it wrote. Print the size on disk from `Bun.write` and the uncompressed size separately. Reported by Cubic on #2061.
1 parent 6f31404 commit 72db247

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎apps/ccusage/scripts/generate-large-fixture.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type FixtureResult = {
7979
fileCount: number;
8080
lineCount: number;
8181
totalBytes: number;
82+
diskBytes: number;
8283
};
8384

8485
type Options = {
@@ -849,7 +850,7 @@ function planCodexFile(directory: string, fileIndex: number): PlannedFile {
849850
async function writeFile(
850851
file: PlannedFile,
851852
targetSize: number,
852-
): Promise<{ bytes: number; lines: number }> {
853+
): Promise<{ bytes: number; diskBytes: number; lines: number }> {
853854
await Bun.$`mkdir -p ${dirname(file.path)}`;
854855
const chunks: string[] = [];
855856
let bytes = 0;
@@ -865,8 +866,11 @@ async function writeFile(
865866
lines += 1;
866867
}
867868
const content = chunks.join('');
868-
await Bun.write(file.path, file.compressed ? Bun.zstdCompressSync(content) : content);
869-
return { bytes, lines };
869+
const diskBytes = await Bun.write(
870+
file.path,
871+
file.compressed ? Bun.zstdCompressSync(content) : content,
872+
);
873+
return { bytes, diskBytes, lines };
870874
}
871875

872876
async function generateFixture(
@@ -882,6 +886,7 @@ async function generateFixture(
882886
await Bun.$`rm -rf ${directory}`;
883887

884888
let totalBytes = 0;
889+
let diskBytes = 0;
885890
let lineCount = 0;
886891
let previousSession: ClaudeSession | undefined;
887892
for (let fileIndex = 0; fileIndex < fileSizeTargets.length; fileIndex += 1) {
@@ -899,17 +904,19 @@ async function generateFixture(
899904
}
900905
const written = await writeFile(file, targetSize);
901906
totalBytes += written.bytes;
907+
diskBytes += written.diskBytes;
902908
lineCount += written.lines;
903909
}
904910

905-
return { fileCount: fileSizeTargets.length, lineCount, totalBytes };
911+
return { fileCount: fileSizeTargets.length, lineCount, totalBytes, diskBytes };
906912
}
907913

908914
function printResult(name: string, outputDir: string, result: FixtureResult): void {
909915
console.log(`Generated ${name} fixture ${outputDir}`);
910916
console.log(`Files: ${result.fileCount}`);
911917
console.log(`Rows: ${result.lineCount}`);
912-
console.log(`Size: ${formatBytes(result.totalBytes)}`);
918+
console.log(`Size on disk: ${formatBytes(result.diskBytes)}`);
919+
console.log(`Uncompressed: ${formatBytes(result.totalBytes)}`);
913920
}
914921

915922
async function main(): Promise<void> {

0 commit comments

Comments
 (0)