Documentation
¶
Overview ¶
Package sizecheck measures a built package (a WebAssembly binary, an Android AAB or APK, or an iOS IPA) and checks it against a size budget, the checks behind `game size`.
Index ¶
- Constants
- func FormatBudgetReport(rep BudgetReport) string
- func FormatMobileReport(rep MobilePackageReport) string
- func FormatWasmMarkdownReport(rep BudgetReport) string
- type BudgetExceededError
- type BudgetFile
- type BudgetReport
- type FileEntry
- type Measurement
- type MobileBudget
- type MobilePackageReport
- func CheckMobilePackage(pkgPath string, kind PackageKind, budget MobileBudget) (MobilePackageReport, error)
- func EvaluateMobileBudget(rep MobilePackageReport, budget MobileBudget) MobilePackageReport
- func InspectMobilePackage(pkgPath string, kind PackageKind) (MobilePackageReport, error)
- func InspectMobileReader(r io.ReaderAt, archiveSize int64, displayPath string, kind PackageKind) (MobilePackageReport, error)
- type PackageKind
- type SizeBreakdown
Constants ¶
const ( // Shared categories. CategoryResources = "resources" CategoryOther = "other" // Android categories (AAB and APK). CategoryNativeLibs = "native_libs" CategoryDEX = "dex" CategoryAssets = "assets" CategoryManifestMeta = "manifest_meta" // iOS categories (IPA). CategoryExecutable = "executable" CategoryFrameworks = "frameworks" CategoryAssetsCar = "assets_car" CategoryLproj = "lproj" CategoryCodeSignature = "code_signature" )
Content category keys for Android AAB/APK and iOS IPA packages.
const DefaultTopLargestFiles = 10
DefaultTopLargestFiles is the default number of largest archive entries kept in MobilePackageReport.LargestFiles.
Variables ¶
This section is empty.
Functions ¶
func FormatBudgetReport ¶
func FormatBudgetReport(rep BudgetReport) string
FormatBudgetReport renders a human-readable summary of rep.
func FormatMobileReport ¶
func FormatMobileReport(rep MobilePackageReport) string
FormatMobileReport renders a GitHub-flavored Markdown summary suitable for terminal output and $GITHUB_STEP_SUMMARY.
func FormatWasmMarkdownReport ¶
func FormatWasmMarkdownReport(rep BudgetReport) string
FormatWasmMarkdownReport renders a Markdown summary for a WebAssembly BudgetReport.
Types ¶
type BudgetExceededError ¶
type BudgetExceededError struct {
Report MobilePackageReport
}
BudgetExceededError is returned by CheckMobilePackage when one or more limits in MobileBudget are exceeded. Its Error text includes all violations and the full Markdown space breakdown.
func (*BudgetExceededError) Error ¶
func (e *BudgetExceededError) Error() string
type BudgetFile ¶
type BudgetFile struct {
Target string `json:"target"`
LDFlags string `json:"ldflags"`
MaxRawBytes int64 `json:"max_raw_bytes"`
MaxGzipBytes int64 `json:"max_gzip_bytes"`
Note string `json:"note,omitempty"`
}
BudgetFile is the JSON schema stored in benchmarks/web-budget.json.
func LoadBudget ¶
func LoadBudget(path string) (BudgetFile, error)
LoadBudget reads and decodes a BudgetFile from path. Its errors are *loaderr.Error values that name path, with the line of the problem and how to fix it.
type BudgetReport ¶
type BudgetReport struct {
Budget BudgetFile `json:"budget"`
Measured Measurement `json:"measured"`
Violations []string `json:"violations,omitempty"`
}
BudgetReport holds the result of comparing a Measurement against a BudgetFile.
func EvaluateBudget ¶
func EvaluateBudget(budget BudgetFile, got Measurement) BudgetReport
EvaluateBudget checks got against budget and returns a BudgetReport.
func (BudgetReport) Passed ¶
func (r BudgetReport) Passed() bool
Passed reports whether both raw and gzipped sizes are within budget.
type FileEntry ¶
type FileEntry struct {
Path string `json:"path"`
Category string `json:"category"`
ABI string `json:"abi,omitempty"`
CompressedBytes int64 `json:"compressed_bytes"`
UncompressedBytes int64 `json:"uncompressed_bytes"`
}
FileEntry describes one file inside a mobile package archive.
type Measurement ¶
Measurement stores measured raw and gzip-compressed WebAssembly sizes.
func MeasureWasm ¶
func MeasureWasm(wasm []byte) (Measurement, error)
MeasureWasm returns the raw and gzipped (BestCompression) byte sizes of wasm.
type MobileBudget ¶
type MobileBudget struct {
// MaxTotalBytes limits the total package archive size on disk.
MaxTotalBytes int64 `json:"max_total_bytes"`
// MaxPerABIBytes limits the compressed native library bytes for any single
// Android ABI (e.g. arm64-v8a, armeabi-v7a, x86_64).
MaxPerABIBytes int64 `json:"max_per_abi_bytes,omitempty"`
// MaxCategoryBytes limits compressed bytes per category key
// (e.g. "native_libs", "dex", "executable", "frameworks").
MaxCategoryBytes map[string]int64 `json:"max_category_bytes,omitempty"`
// Note documents the rationale behind the budget thresholds.
Note string `json:"note,omitempty"`
}
MobileBudget defines size budgets (in bytes) for Android AAB/APK and iOS IPA packages. Any limit <= 0 is treated as unbounded.
func DefaultAndroidAABBudget ¶
func DefaultAndroidAABBudget() MobileBudget
DefaultAndroidAABBudget returns the documented default size budget for an Android App Bundle (.aab).
Google Play caps per-device base-module downloads at 200 MiB. Keeping the combined AAB within 50 MiB total and 20 MiB per native ABI leaves headroom for game assets while preserving fast mobile install conversion.
func DefaultAndroidAPKBudget ¶
func DefaultAndroidAPKBudget() MobileBudget
DefaultAndroidAPKBudget returns the documented default size budget for an Android APK (.apk).
Multi-ABI APKs ship native libraries for every targeted ABI directly in the installable file. Keeping APKs within 40 MiB total and 20 MiB per ABI keeps direct downloads lean (well below the 100 MiB legacy APK ceiling).
func DefaultIOSIPABudget ¶
func DefaultIOSIPABudget() MobileBudget
DefaultIOSIPABudget returns the documented default size budget for an iOS App Store Package (.ipa).
Apple enforces a 200 MiB cellular download threshold. Keeping IPAs within 50 MiB total ensures fast cellular downloads even before App Thinning.
func DefaultMobileBudget ¶
func DefaultMobileBudget(kind PackageKind) (MobileBudget, error)
DefaultMobileBudget returns the default MobileBudget for kind.
func LoadMobileBudget ¶
func LoadMobileBudget(filePath string) (MobileBudget, error)
LoadMobileBudget reads and decodes a MobileBudget JSON file from filePath. Its errors are *loaderr.Error values that name filePath, with the line of the problem and how to fix it.
type MobilePackageReport ¶
type MobilePackageReport struct {
Path string `json:"path"`
Kind PackageKind `json:"kind"`
ArchiveBytes int64 `json:"archive_bytes"`
CompressedBytes int64 `json:"compressed_bytes"`
UncompressedBytes int64 `json:"uncompressed_bytes"`
FileCount int `json:"file_count"`
Categories map[string]SizeBreakdown `json:"categories"`
ABIs map[string]SizeBreakdown `json:"abis,omitempty"`
LargestFiles []FileEntry `json:"largest_files"`
Budget MobileBudget `json:"budget"`
Violations []string `json:"violations,omitempty"`
Passed bool `json:"passed"`
}
MobilePackageReport holds the full size breakdown and budget evaluation for an Android AAB/APK or iOS IPA archive.
func CheckMobilePackage ¶
func CheckMobilePackage(pkgPath string, kind PackageKind, budget MobileBudget) (MobilePackageReport, error)
CheckMobilePackage inspects pkgPath as kind and enforces budget.
When the archive is readable, CheckMobilePackage always returns the populated MobilePackageReport. If any budget limit is exceeded, it also returns a *BudgetExceededError whose message contains every violation and the full Markdown space breakdown.
func EvaluateMobileBudget ¶
func EvaluateMobileBudget(rep MobilePackageReport, budget MobileBudget) MobilePackageReport
EvaluateMobileBudget evaluates an inspected MobilePackageReport against budget, populating Budget, Violations, and Passed.
func InspectMobilePackage ¶
func InspectMobilePackage(pkgPath string, kind PackageKind) (MobilePackageReport, error)
InspectMobilePackage opens the ZIP-based mobile archive at pkgPath and computes its category, ABI, and largest-file breakdowns.
func InspectMobileReader ¶
func InspectMobileReader(r io.ReaderAt, archiveSize int64, displayPath string, kind PackageKind) (MobilePackageReport, error)
InspectMobileReader inspects a ZIP-based mobile package from r with total archive byte length archiveSize.
type PackageKind ¶
type PackageKind string
PackageKind identifies the package artifact format inspected by sizecheck.
const ( PackageKindWasm PackageKind = "wasm" PackageKindAAB PackageKind = "aab" PackageKindAPK PackageKind = "apk" PackageKindIPA PackageKind = "ipa" )
func DetectPackageKind ¶
func DetectPackageKind(filePath string) (PackageKind, bool)
DetectPackageKind infers a PackageKind from filePath's extension.
func ParsePackageKind ¶
func ParsePackageKind(raw string) (PackageKind, error)
ParsePackageKind parses a CLI -kind value into a PackageKind.
type SizeBreakdown ¶
type SizeBreakdown struct {
CompressedBytes int64 `json:"compressed_bytes"`
UncompressedBytes int64 `json:"uncompressed_bytes"`
FileCount int `json:"file_count"`
}
SizeBreakdown holds compressed and uncompressed byte totals plus entry count for a single category or ABI bucket.