Skip to content

refactor: clean up minification benchmark data typing#150

Merged
fengmk2 merged 1 commit intovoidzero-dev:mainfrom
yangshun:refactor/minification-data-types
Mar 20, 2026
Merged

refactor: clean up minification benchmark data typing#150
fengmk2 merged 1 commit intovoidzero-dev:mainfrom
yangshun:refactor/minification-data-types

Conversation

@yangshun
Copy link
Contributor

@yangshun yangshun commented Mar 20, 2026

Summary

  • replace repeated inline minifier label/color mapping with a single typed minifier definition list
  • add typed helpers for library benchmark data and metric conversion
  • parse imported benchmark JSON into a validated structure instead of relying on an unsafe narrowing cast

Test plan

image
  • vp check
  • vp run build

import minificationData from "../../../data/minification-benchmarks-data.json";

export const popularMinifiers = ["terser", "esbuild", "@swc/core", "uglify-js", "oxc-minify"];
const MINIFIERS = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes the need for long if/else chain in the original function.

Adding new minifiers will now be easier, just add it as a new item in the array.

);
}

function getBenchmarkData(data: unknown): MinificationBenchmarkData {
Copy link
Contributor Author

@yangshun yangshun Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous version used any, which is not typesafe.

Unfortunately it takes 60 more lines of code to make TypeScript happy. Happy to revert back to any if not desired / deemed overkill.

value = Math.round(((originalSize - minzippedBytes) / originalSize) * 100 * 10) / 10;
}

data.push({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main aim was to remove this.

Copy link
Member

@fengmk2 fengmk2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangshun Thanks!

@fengmk2 fengmk2 merged commit badb2c3 into voidzero-dev:main Mar 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants