perf: Optimize Invariant Caching & Number Formatting in Hot Paths#1866
Open
hluaguo wants to merge 3 commits into
Open
perf: Optimize Invariant Caching & Number Formatting in Hot Paths#1866hluaguo wants to merge 3 commits into
hluaguo wants to merge 3 commits into
Conversation
Convert computed static properties to static let constants, avoiding redundant ProcessInfo queries and memory parsing on every access.
Convert computed static properties to static let constants, preventing redundant C FFI version checks and string interpolations on every access.
Replace custom NumberFormatter creation per-call with Swift's native value-type formatted(.number) API, avoiding heavy formatter allocations and locale introspection.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Type of Change
Motivation and Context
This pull request introduces three performance optimization candidates aimed at eliminating redundant heap allocations, expensive system environment queries, and C FFI bridging overhead in configuration lookups and progress rendering loops:
Cache Machine Configuration Defaults (MachineConfig.swift):
static var) queriedProcessInfoand parsed memory unit strings on every single call.static let) compute values once on first access.Cache Build & Vminit Default Image URIs (ContainerSystemConfig.swift):
Replace Legacy NumberFormatter with Native Swift FormatStyle (Int+Formatted.swift):
NumberFormatterper call, invoking locale introspection and loading system ICU tables..formatted(.number)style which utilizes a shared pre-cached formatter store.Testing
Testing Details:
ContainerPersistenceTestsandTerminalProgressTeststargets successfully with 0 failures.formattedNumber()behavior using a cross-locale differential testing suite (comparing againstNumberFormatterforen_US,fr_FR,de_DE,zh_CN,ar_SA,hi_INacross multiple boundary inputs:Int.max,Int.min, negative values, and zero), confirming 100% semantic parity.withTaskGroupwith 500 tasks, validating thread safety under race-condition tests.