Conversation
5 tasks
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.
Summary
Cache the 256 sRGB/Display P3 transfer-function values so RGB-to-OKLCH conversion reuses them instead of evaluating the same power function for every pixel channel.
Background
Both input transfer functions accept
UInt8and use the same formula. Repeated image extraction therefore recomputes one of only 256 possibleDoublevalues for each channel. The default OKLCH extraction path pays this cost across all sampled pixels.Solution
Build one private, immutable table using the existing formula and index it from both transfer functions. Matrix operations, inverse conversion, precision, sampling, and public APIs stay the same. Swift initializes the table once on first use; its element storage is approximately 2 KiB.
Related Issue
N/A.
Verification
Double.bitPatternequality and all-channel round trips. The same tests pass on the unmodified base.swift package resolveswift build -c debugswift test --filter OKLCHConversionTests— 2 tests passed.swift test --filter PaletteKitTests --filter PaletteKitInsightsTests— 61 tests passed.swift test -c release --filter OKLCHConversionTests— 2 tests passed.swift test -c release --skip-build --filter OKLCHConversionBenchmarks— 2 benchmarks passed in each comparison run.git diff --checkCompatibility and Impact
Additional Context
Release benchmark medians for 100,000 deterministic pseudo-random pixels; 15
XCTClockMetricsamples per case from three process runs with baseline/candidate order alternated:2286664Run
swift test -c release --filter OKLCHConversionBenchmarksto reproduce. For the baseline, use2286664with only the new benchmark file copied unchanged. These numbers cover conversion and output allocation; they exclude image decode, sampling, quantization, and first-use initialization. They do not establish a corresponding full-API or iPhone improvement percentage.This branch is based directly on
mainand can be reviewed independently.Checklist