SPB Git

Repository Public License

performance.md 16.0 KB

# Performance

Every number on this page was printed by the engines' own tests during one run of Scripts/benchmark.sh on 2026-11-21. Nothing here was measured on an iPhone or an iPad: see Not measured.

# How the numbers were produced

bash
Scripts/benchmark.sh                 # every engine package that prints measurements
Scripts/benchmark.sh ORIXURLRisk     # one package

For each package the script runs swift test -c release -Xswiftc -enable-testing --scratch-path build/bench-scratch/<package>, stores the full output in build/benchmarks/<package>.txt and prints the lines the tests wrote with print(...). -enable-testing keeps @testable import working in an optimized build. The scratch path keeps the release objects out of the packages' default .build folders and out of build/DerivedData.

Date 2026-11-21
Host Mac17,6, Apple M5 Max, 18 cores, 48 GB
System macOS 27.0 (26A5425a)
Toolchain Xcode 27.2 (27B52), Apple Swift 6.4.2
Build release (swift test -c release), macOS arm64 slice of each package
Network Wi-Fi, online; a tunnel interface (utun4) was up

Reading the figures:

  • They are single runs, not averages over repeated runs. Swift Testing runs suites in parallel, so a timing can include contention from other tests of the same package (the Performance suite of ORIXMediaCleanup is serialized internally, but still runs next to the other suites).
  • Inputs are synthetic and generated by the tests (zero-filled or sparse files, generated images, generated fingerprints). File figures are read from the Mac's SSD with a warm cache.
  • The live network figures depend on this network at this minute and are not properties of the app.

Source: Packages/ORIXURLRisk/Tests/ORIXURLRiskTests/AnalyzerTests.swift (suites "Corpora" and "Robustness and timing").

Measurement Result
Mean analysis time, 5 typical links, 1 000 runs 0.250 ms per link
10 000-character input, slowest shape ("many nested") 6.87 ms
10 000-character input, fastest shape ("random") 0.56 ms
Test limit for any 10 000-character input 100 ms

All twelve 10 000-character shapes, as printed:

Input shape Time Input shape Time
long path 2.14 ms many at signs 1.24 ms
long query 1.26 ms many colons 0.82 ms
long host 1.14 ms unicode (with bidi override) 2.13 ms
many labels 1.62 ms redirect values 5.40 ms
many escapes 3.55 ms spaces 1.01 ms
many nested 6.87 ms random 0.56 ms

The same run also printed the corpus results (quality, not speed):

Corpus Links No signals Low Elevated High
Benign 119 89 28 2 0
Suspicious 92 4 31 37 20

Benign links rated above "low": 2 of 119 = 1.68 % (https://www.paypal-community.com/ and https://www.googleadservices.com/pagead/aclk?sa=L&ai=abc, both through the url.brand.embedded signal). The test fails above 5 % or on any benign link rated "high". See testing.md.

# ORIXFileInspection — files, archives, folders

Sources: HashTests.swift, ArchiveTests.swift, InspectorTests.swift, FolderToolsTests.swift.

Measurement Result
Streamed SHA-256 of a 64 MB file 0.035 s = 1 830 MB/s
Peak resident memory growth during that hash 20 688 KiB
ZIP central directory, 150 000 entries written, walk cut at 100 000 (8 MB of directory) 0.15 s
Inspection of a 300 MB sparse PDF, hashing off 0.005 s
Large-file scan of a folder of 5 000 files 0.034 s (145 930 files/s)
Duplicate scan of the same 5 000 files 0.047 s, 207 groups

Notes: the 64 MB file is created with truncate, so it is all zeros and sparse on disk — the figure is the hashing rate with almost no disk cost. The 5 000 files of the folder test are small generated files. The 300 MB PDF figure shows that the inspector reads two bounded windows and not the whole file; it is not a throughput.

# ORIXMediaCleanup — fingerprints, grouping, cache

Sources: PerformanceTests.swift, CacheTests.swift, FingerprintTests.swift, AnalyzerTests.swift, PlanAndLibraryTests.swift.

Measurement Result
Fingerprint of a 128 × 96 image (dHash + pHash + luminance + colour signature), one thread 1 000 images in 0.1007 s → 9 925 images/s
Grouping 10 000 items 0.013 s; 1 417 similar groups, 59 exact groups
Grouping 50 000 items 0.077 s; 7 225 similar groups, 281 exact groups
Grouping 50 000 items with the optional global pass 0.106 s
Dense session: 5 000 alike photos in one capture session 0.014 s; 50 groups, largest 100
Peak memory growth while grouping (10 000 and 50 000 items) printed as 0 MB (whole megabytes; see note)
Fingerprint cache, 20 000 entries 1 708 910 bytes on disk; save + load 0.0126 s
Analysis returns after cancellation 0.0052 s
Scan pipeline returns after cancellation 0.000078 s

Notes:

  • The grouping tests start from items that already carry a fingerprint (SyntheticLibrary.items). They measure the grouping engine only. On a device the dominant cost of a first scan is obtaining thumbnails from Photos, which no host test can measure.
  • The fingerprint figure starts from an image already in memory at 128 × 96. Thumbnail decoding by Photos is not included.
  • "0 MB" is the growth of the process's peak resident size (getrusage, ru_maxrss), integer-divided by 1 MiB, after earlier tests in the same process had already raised the peak. It shows that grouping did not push the peak higher by a megabyte in this run; it is not a measurement of the memory the grouping uses.

Fingerprint quality on generated scenes, printed by the same run (60 scenes; distances as mean / p95 / max):

Transformation dHash pHash Colour Luma Match rate at default thresholds
identical copy 0.0 / 0 / 0 0.0 / 0 / 0 0.0 / 0 / 0 0.0 / 0 / 0 1.00
JPEG q = 0.90 1.8 / 6 / 8 0.9 / 2 / 4 0.0 / 0 / 0 0.2 / 1 / 1 1.00
JPEG q = 0.60 1.6 / 7 / 8 0.8 / 2 / 4 0.0 / 0 / 0 0.1 / 1 / 1 1.00
JPEG q = 0.35 1.9 / 6 / 7 0.8 / 2 / 4 0.0 / 0 / 0 0.2 / 1 / 1 1.00
resize 50 % 1.3 / 4 / 6 0.6 / 2 / 2 0.0 / 0 / 0 0.1 / 1 / 1 1.00
resize 150 % 1.1 / 3 / 8 0.2 / 2 / 2 0.0 / 0 / 0 0.2 / 1 / 1 1.00
brightness +18 1.8 / 5 / 9 1.0 / 4 / 4 0.0 / 0 / 1 16.8 / 18 / 18 0.98
crop 2 % 3.7 / 10 / 12 3.4 / 6 / 6 1.7 / 3 / 3 0.7 / 2 / 2 0.95
shift 2 % 7.2 / 13 / 16 5.1 / 8 / 10 2.6 / 4 / 4 0.5 / 1 / 1 0.62
red/blue swapped 7.0 / 18 / 20 8.2 / 16 / 18 35.7 / 61 / 73 6.6 / 15 / 24 0.00

Unrelated pairs: 0 matches of 1 770 (minimum dHash distance 14, minimum pHash distance 14). Grouping on 360 generated images of 40 scenes: 43 groups, 0 mixed-scene groups, pair precision 1.000, pair recall 0.960 (re-encode/resize recall 0.965). These are results on generated pictures, not on photographs.

# ORIXReporting — PDF

Source: Packages/ORIXReporting/Tests/ORIXReportingTests/PDFTests.swift.

Measurement Result
PDF of a report with 300 findings (US Letter) 399 ms, 632 202 bytes, 151 pages

# ORIXNetworkLab — live probes and parser fuzzing

Sources: LiveTests.swift, LogicTests.swift, X509Tests.swift. The live figures describe this Mac's network at the time of the run.

Measurement Result
TLS inspection of apple.com:443 59 ms; TLS 1.3, TLS_AES_256_GCM_SHA384, chain of 3 certificates
TLS inspection of a loopback openssl s_server 10 ms; TLS 1.3
DNS apple.com (system resolver, likely cached) 0.6 ms; 1 A, 1 AAAA
DNS nonexistent.invalid "not found" in 0.7 ms
DNS localhost 0.8 ms
DNS lookup with a 1 ms budget timeout reported after 1.67 ms
TCP connect latency apple.com:443, 5 samples median 19 ms, average 38 ms, min 17 ms, max 83 ms, jitter 26 ms, 0 lost
TCP connect latency, loopback, 5 samples median 0.6 ms, min 0.4 ms, max 0.8 ms
Blackhole address with a 1 000 ms budget TCP: 2 attempts in 2.14 s; TLS: 1.03 s
HTTPS probe http://apple.com/ 111 ms; 2 hops (301 → 200), HSTS present
Bonjour browse bounded at 2 s; 9 services found on this LAN
X.509 mutation fuzz (4 000 mutated certificates) 1 896 rejected with a typed error, 2 104 still structurally valid, 0 crashes

# ORIXSecureEngines — device probe

DeviceStoragePrivacyTests.swift prints what the probe returns on the host (arm64, macOS 27.0, memory footprint of the test process 10 764 984 B, 25 integrity checks performed). It is a sanity print, not a benchmark, and the values describe the Mac's test process, not the app.

# Not measured

No physical iPhone or iPad was available. The following have no figure in this repository, and none should be quoted until someone measures them:

Not measured Why the host figures do not transfer
Any timing on an iPhone or iPad The engines ran as macOS binaries on an M5 Max. iPhone processors are slower and the system throttles under heat and Low Power Mode. The ratio is unknown.
Real photo-library scan speed A first scan is dominated by PHImageManager thumbnail requests, which depend on the library, the device and whether originals are local. The host tests never touch Photos. The Simulator run only covered a dozen generated images.
Memory on device The only memory figures are peak-resident deltas of a macOS test process. App footprint, memory during a large scan and behaviour under memory pressure are unmeasured.
Battery impact Not measurable on a Mac or in the Simulator.
Launch time, scrolling and animation smoothness Not measured anywhere; UI tests assert behaviour, not frame times.
App size on device No App Store build was thinned and measured for this page.
Network figures on cellular The live tests ran on Wi-Fi on a Mac.

# How to measure them

On a physical device, with a Release build:

  1. Time and CPU — Instruments, Time Profiler, on a first Photo Cleanup scan and on a re-scan. The scan reports ScanStatistics.duration, fingerprintsComputed and fingerprintCacheHits (Packages/ORIXMediaCleanup/Sources/ORIXMediaCleanup/PhotoLibraryScanner.swift); divide the number of assets by the duration for a real images-per-second figure, and record the device model, iOS version and library size next to it.
  2. Memory — Instruments, Allocations and VM Tracker, or Xcode's memory gauge, during the scan of a large library, a 1 GB file hash and the 300-finding PDF. Record the peak footprint, not the average.
  3. Battery and energy — Instruments, Energy Log, or Xcode Organizer's energy metrics after TestFlight use. A scan of a known library size from a known battery level is the simplest repeatable test.
  4. Launch time and hangs — Instruments, App Launch template; Xcode Organizer for launch and hang rates once a build is in TestFlight.
  5. Field data — MetricKit (MXMetricManager) can deliver daily launch, memory, CPU and energy payloads from real devices. The app does not subscribe to MetricKit today; adding it would be a code change and would have to respect the "nothing leaves the device" rule (payloads kept local).
  6. Engine timings on device — the same measurement tests can run on a device if the packages' tests are added to an Xcode test plan with an iOS destination. This is not set up.

Write the device, OS version, build number, library size and date next to every figure that is added here.

# Design choices that keep the app light

Each point names the code that implements it.

  • Incremental photo scan in batches. PhotoLibraryScanner.scan walks the fetch result batchSize assets at a time (default 200), inside an autoreleasepool, and reports progress and checks cancellation between batches. Thumbnail requests run with bounded concurrency (concurrentThumbnailRequests, default 4). Packages/ORIXMediaCleanup/Sources/ORIXMediaCleanup/PhotoLibraryScanner.swift
  • Thumbnail-sized fingerprints. Fingerprints are computed from thumbnails whose longest side is thumbnailPixelSize (default 128 px), never from full-resolution originals. Requests set isNetworkAccessAllowed = false, so nothing is downloaded from iCloud. Same file, fingerprint(of:pixelSize:); the fingerprint itself is in ImageFingerprint.swift (64-bit dHash, 64-bit pHash, mean luminance, 4 × 4 colour signature).
  • Persistent fingerprint cache. FingerprintCache keys each fingerprint by asset identifier and modification date, so a re-scan only fingerprints new or changed assets. The file is versioned and checksummed; a corrupt or outdated file is discarded, and entries for assets that no longer exist are pruned. The cache is saved before a cancelled scan throws. FingerprintCache.swift, PhotoLibraryScanner.swift
  • Exact sizes and hashes only for candidates. PhotoSizeMeasurer streams resource data (bytes counted and hashed in one pass) and is only asked about group members and the longest videos, not the whole library (test "Pipeline: only candidates are measured"). PhotoSizeMeasurer.swift, MediaLibrary.swift
  • Bounded grouping. Visual similarity is evaluated inside capture sessions with a lookback limit, so work grows roughly linearly with the library; the cross-session global pass is off by default (CleanupConfiguration.globalPassEnabled). The performance test fails if 5× the items cost more than 15× the time. CleanupAnalyzer.swift
  • Streaming hashes. FileHasher.sha256 reads chunkSize bytes at a time (default 1 MiB, clamped to 4 KiB–16 MiB) inside an autoreleasepool, checks cancellation on every chunk and yields every 32 chunks. Packages/ORIXFileInspection/Sources/ORIXFileInspection/FileHasher.swift
  • Duplicate search without hashing everything. Files are grouped by size, then by SHA-256 of the first 64 KiB, and only the remaining candidates are hashed in full. DuplicateFinder.swift
  • Bounded parsers. Every parser reads untrusted bytes through ByteSource (bounded random access, overflow-safe integers). Limits live in InspectionOptions: 100 000 archive entries walked, 500 reported, raw scans limited to an 8 MiB window at each end of the file, PDFKit not used above 256 MiB, 500 pages / 200 links for PDF links. Archives are never extracted or inflated. ByteSource.swift, InspectionOptions.swift, ZipInspector.swift, TarGzipInspector.swift
  • Bounded DER parsing. The certificate parser stops at a nesting depth of 24 and 50 000 elements and throws typed errors. Packages/ORIXNetworkLab/Sources/ORIXNetworkLab/DER.swift
  • Bounded link analysis. Evidence strings are clipped and the path scan is limited to its first 2 000 characters; a 300 000-character input is refused as unparsed in under 100 ms (test longInputsAreBounded). Packages/ORIXURLRisk/Sources/ORIXURLRisk/URLRiskAnalyzer.swift
  • Every network probe has a timeout. TLS 10 s, DNS 5 s, TCP latency 3 s per attempt, HTTPS 10 s, path snapshot 2 s by default; DNS lookups are limited to 4 at a time. TLSInspector.swift, DNSProbe.swift, LatencyProbe.swift, HTTPSProbe.swift, ConnectivityMonitor.swift
  • Cancellation everywhere. Engines call Task.checkCancellation() / check Task.isCancelled (analyzer, scanner, measurer, hasher, folder walker, workflow runner), and the screens expose a Cancel control that cancels the task (PhotoCleanupController.cancel, FileScannerView, FileCleanupView, ActionsController.cancel).
  • No background work. App/Resources/Info.plist declares no UIBackgroundModes, and the app sources contain no BGTaskScheduler or beginBackgroundTask call. Scans and probes run only while the user is looking at them.
  • No third-party code. Every package dependency is a local path (Scripts/check.sh fails on a remote one), so there is no analytics, advertising or networking SDK adding launch time or background activity.
Files main
Menu

Theme