SPB Git

Repository Public License

performance.md 16.0 KB 255 lines markdown

1<!--2ORIX Secure3File: docs/development/performance.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->78# Performance910Every number on this page was printed by the engines' own tests during one run of `Scripts/benchmark.sh` on112026-11-21. Nothing here was measured on an iPhone or an iPad: see [Not measured](#not-measured).1213## How the numbers were produced1415```bash16Scripts/benchmark.sh                 # every engine package that prints measurements17Scripts/benchmark.sh ORIXURLRisk     # one package18```1920For each package the script runs `swift test -c release -Xswiftc -enable-testing --scratch-path build/bench-scratch/<package>`,21stores the full output in `build/benchmarks/<package>.txt` and prints the lines the tests wrote with `print(...)`.22`-enable-testing` keeps `@testable import` working in an optimized build. The scratch path keeps the release objects23out of the packages' default `.build` folders and out of `build/DerivedData`.2425| | |26|---|---|27| Date | 2026-11-21 |28| Host | `Mac17,6`, Apple M5 Max, 18 cores, 48 GB |29| System | macOS 27.0 (26A5425a) |30| Toolchain | Xcode 27.2 (27B52), Apple Swift 6.4.2 |31| Build | release (`swift test -c release`), macOS arm64 slice of each package |32| Network | Wi-Fi, online; a tunnel interface (`utun4`) was up |3334Reading the figures:3536- They are single runs, not averages over repeated runs. Swift Testing runs suites in parallel, so a timing can include37  contention from other tests of the same package (the `Performance` suite of ORIXMediaCleanup is serialized internally,38  but still runs next to the other suites).39- Inputs are synthetic and generated by the tests (zero-filled or sparse files, generated images, generated40  fingerprints). File figures are read from the Mac's SSD with a warm cache.41- The live network figures depend on this network at this minute and are not properties of the app.4243## ORIXURLRisk — link analysis4445Source: `Packages/ORIXURLRisk/Tests/ORIXURLRiskTests/AnalyzerTests.swift` (suites "Corpora" and "Robustness and timing").4647| Measurement | Result |48|---|---|49| Mean analysis time, 5 typical links, 1 000 runs | 0.250 ms per link |50| 10 000-character input, slowest shape ("many nested") | 6.87 ms |51| 10 000-character input, fastest shape ("random") | 0.56 ms |52| Test limit for any 10 000-character input | 100 ms |5354All twelve 10 000-character shapes, as printed:5556| Input shape | Time | Input shape | Time |57|---|---|---|---|58| long path | 2.14 ms | many at signs | 1.24 ms |59| long query | 1.26 ms | many colons | 0.82 ms |60| long host | 1.14 ms | unicode (with bidi override) | 2.13 ms |61| many labels | 1.62 ms | redirect values | 5.40 ms |62| many escapes | 3.55 ms | spaces | 1.01 ms |63| many nested | 6.87 ms | random | 0.56 ms |6465The same run also printed the corpus results (quality, not speed):6667| Corpus | Links | No signals | Low | Elevated | High |68|---|---|---|---|---|---|69| Benign | 119 | 89 | 28 | 2 | 0 |70| Suspicious | 92 | 4 | 31 | 37 | 20 |7172Benign links rated above "low": 2 of 119 = 1.68 % (`https://www.paypal-community.com/` and73`https://www.googleadservices.com/pagead/aclk?sa=L&ai=abc`, both through the `url.brand.embedded` signal). The test fails74above 5 % or on any benign link rated "high". See [testing.md](testing.md).7576## ORIXFileInspection — files, archives, folders7778Sources: `HashTests.swift`, `ArchiveTests.swift`, `InspectorTests.swift`, `FolderToolsTests.swift`.7980| Measurement | Result |81|---|---|82| Streamed SHA-256 of a 64 MB file | 0.035 s = 1 830 MB/s |83| Peak resident memory growth during that hash | 20 688 KiB |84| ZIP central directory, 150 000 entries written, walk cut at 100 000 (8 MB of directory) | 0.15 s |85| Inspection of a 300 MB sparse PDF, hashing off | 0.005 s |86| Large-file scan of a folder of 5 000 files | 0.034 s (145 930 files/s) |87| Duplicate scan of the same 5 000 files | 0.047 s, 207 groups |8889Notes: the 64 MB file is created with `truncate`, so it is all zeros and sparse on disk — the figure is the hashing rate90with almost no disk cost. The 5 000 files of the folder test are small generated files. The 300 MB PDF figure shows that91the inspector reads two bounded windows and not the whole file; it is not a throughput.9293## ORIXMediaCleanup — fingerprints, grouping, cache9495Sources: `PerformanceTests.swift`, `CacheTests.swift`, `FingerprintTests.swift`, `AnalyzerTests.swift`, `PlanAndLibraryTests.swift`.9697| Measurement | Result |98|---|---|99| Fingerprint of a 128 × 96 image (dHash + pHash + luminance + colour signature), one thread | 1 000 images in 0.1007 s → 9 925 images/s |100| Grouping 10 000 items | 0.013 s; 1 417 similar groups, 59 exact groups |101| Grouping 50 000 items | 0.077 s; 7 225 similar groups, 281 exact groups |102| Grouping 50 000 items with the optional global pass | 0.106 s |103| Dense session: 5 000 alike photos in one capture session | 0.014 s; 50 groups, largest 100 |104| Peak memory growth while grouping (10 000 and 50 000 items) | printed as 0 MB (whole megabytes; see note) |105| Fingerprint cache, 20 000 entries | 1 708 910 bytes on disk; save + load 0.0126 s |106| Analysis returns after cancellation | 0.0052 s |107| Scan pipeline returns after cancellation | 0.000078 s |108109Notes:110111- The grouping tests start from items that already carry a fingerprint (`SyntheticLibrary.items`). They measure the112  grouping engine only. On a device the dominant cost of a first scan is obtaining thumbnails from Photos, which no113  host test can measure.114- The fingerprint figure starts from an image already in memory at 128 × 96. Thumbnail decoding by Photos is not included.115- "0 MB" is the growth of the process's peak resident size (`getrusage`, `ru_maxrss`), integer-divided by 1 MiB, after116  earlier tests in the same process had already raised the peak. It shows that grouping did not push the peak higher by117  a megabyte in this run; it is not a measurement of the memory the grouping uses.118119Fingerprint quality on generated scenes, printed by the same run (60 scenes; distances as mean / p95 / max):120121| Transformation | dHash | pHash | Colour | Luma | Match rate at default thresholds |122|---|---|---|---|---|---|123| identical copy | 0.0 / 0 / 0 | 0.0 / 0 / 0 | 0.0 / 0 / 0 | 0.0 / 0 / 0 | 1.00 |124| JPEG q = 0.90 | 1.8 / 6 / 8 | 0.9 / 2 / 4 | 0.0 / 0 / 0 | 0.2 / 1 / 1 | 1.00 |125| JPEG q = 0.60 | 1.6 / 7 / 8 | 0.8 / 2 / 4 | 0.0 / 0 / 0 | 0.1 / 1 / 1 | 1.00 |126| JPEG q = 0.35 | 1.9 / 6 / 7 | 0.8 / 2 / 4 | 0.0 / 0 / 0 | 0.2 / 1 / 1 | 1.00 |127| resize 50 % | 1.3 / 4 / 6 | 0.6 / 2 / 2 | 0.0 / 0 / 0 | 0.1 / 1 / 1 | 1.00 |128| resize 150 % | 1.1 / 3 / 8 | 0.2 / 2 / 2 | 0.0 / 0 / 0 | 0.2 / 1 / 1 | 1.00 |129| brightness +18 | 1.8 / 5 / 9 | 1.0 / 4 / 4 | 0.0 / 0 / 1 | 16.8 / 18 / 18 | 0.98 |130| crop 2 % | 3.7 / 10 / 12 | 3.4 / 6 / 6 | 1.7 / 3 / 3 | 0.7 / 2 / 2 | 0.95 |131| shift 2 % | 7.2 / 13 / 16 | 5.1 / 8 / 10 | 2.6 / 4 / 4 | 0.5 / 1 / 1 | 0.62 |132| red/blue swapped | 7.0 / 18 / 20 | 8.2 / 16 / 18 | 35.7 / 61 / 73 | 6.6 / 15 / 24 | 0.00 |133134Unrelated pairs: 0 matches of 1 770 (minimum dHash distance 14, minimum pHash distance 14). Grouping on 360 generated135images of 40 scenes: 43 groups, 0 mixed-scene groups, pair precision 1.000, pair recall 0.960 (re-encode/resize recall1360.965). These are results on generated pictures, not on photographs.137138## ORIXReporting — PDF139140Source: `Packages/ORIXReporting/Tests/ORIXReportingTests/PDFTests.swift`.141142| Measurement | Result |143|---|---|144| PDF of a report with 300 findings (US Letter) | 399 ms, 632 202 bytes, 151 pages |145146## ORIXNetworkLab — live probes and parser fuzzing147148Sources: `LiveTests.swift`, `LogicTests.swift`, `X509Tests.swift`. The live figures describe this Mac's network at the149time of the run.150151| Measurement | Result |152|---|---|153| TLS inspection of `apple.com:443` | 59 ms; TLS 1.3, `TLS_AES_256_GCM_SHA384`, chain of 3 certificates |154| TLS inspection of a loopback `openssl s_server` | 10 ms; TLS 1.3 |155| DNS `apple.com` (system resolver, likely cached) | 0.6 ms; 1 A, 1 AAAA |156| DNS `nonexistent.invalid` | "not found" in 0.7 ms |157| DNS `localhost` | 0.8 ms |158| DNS lookup with a 1 ms budget | timeout reported after 1.67 ms |159| 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 |160| TCP connect latency, loopback, 5 samples | median 0.6 ms, min 0.4 ms, max 0.8 ms |161| Blackhole address with a 1 000 ms budget | TCP: 2 attempts in 2.14 s; TLS: 1.03 s |162| HTTPS probe `http://apple.com/` | 111 ms; 2 hops (301 → 200), HSTS present |163| Bonjour browse | bounded at 2 s; 9 services found on this LAN |164| X.509 mutation fuzz (4 000 mutated certificates) | 1 896 rejected with a typed error, 2 104 still structurally valid, 0 crashes |165166## ORIXSecureEngines — device probe167168`DeviceStoragePrivacyTests.swift` prints what the probe returns on the host (`arm64`, macOS 27.0, memory footprint of169the test process 10 764 984 B, 25 integrity checks performed). It is a sanity print, not a benchmark, and the values170describe the Mac's test process, not the app.171172## Not measured173174No physical iPhone or iPad was available. The following have **no figure in this repository**, and none should be175quoted until someone measures them:176177| Not measured | Why the host figures do not transfer |178|---|---|179| 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. |180| 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. |181| 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. |182| Battery impact | Not measurable on a Mac or in the Simulator. |183| Launch time, scrolling and animation smoothness | Not measured anywhere; UI tests assert behaviour, not frame times. |184| App size on device | No App Store build was thinned and measured for this page. |185| Network figures on cellular | The live tests ran on Wi-Fi on a Mac. |186187### How to measure them188189On a physical device, with a Release build:1901911. **Time and CPU** — Instruments, *Time Profiler*, on a first Photo Cleanup scan and on a re-scan. The scan reports192   `ScanStatistics.duration`, `fingerprintsComputed` and `fingerprintCacheHits`193   (`Packages/ORIXMediaCleanup/Sources/ORIXMediaCleanup/PhotoLibraryScanner.swift`); divide the number of assets by the194   duration for a real images-per-second figure, and record the device model, iOS version and library size next to it.1952. **Memory** — Instruments, *Allocations* and *VM Tracker*, or Xcode's memory gauge, during the scan of a large196   library, a 1 GB file hash and the 300-finding PDF. Record the peak footprint, not the average.1973. **Battery and energy** — Instruments, *Energy Log*, or Xcode Organizer's energy metrics after TestFlight use. A198   scan of a known library size from a known battery level is the simplest repeatable test.1994. **Launch time and hangs** — Instruments, *App Launch* template; Xcode Organizer for launch and hang rates once a200   build is in TestFlight.2015. **Field data** — MetricKit (`MXMetricManager`) can deliver daily launch, memory, CPU and energy payloads from real202   devices. The app does not subscribe to MetricKit today; adding it would be a code change and would have to respect203   the "nothing leaves the device" rule (payloads kept local).2046. **Engine timings on device** — the same measurement tests can run on a device if the packages' tests are added to205   an Xcode test plan with an iOS destination. This is not set up.206207Write the device, OS version, build number, library size and date next to every figure that is added here.208209## Design choices that keep the app light210211Each point names the code that implements it.212213- **Incremental photo scan in batches.** `PhotoLibraryScanner.scan` walks the fetch result `batchSize` assets at a time214  (default 200), inside an `autoreleasepool`, and reports progress and checks cancellation between batches. Thumbnail215  requests run with bounded concurrency (`concurrentThumbnailRequests`, default 4).216  `Packages/ORIXMediaCleanup/Sources/ORIXMediaCleanup/PhotoLibraryScanner.swift`217- **Thumbnail-sized fingerprints.** Fingerprints are computed from thumbnails whose longest side is218  `thumbnailPixelSize` (default 128 px), never from full-resolution originals. Requests set219  `isNetworkAccessAllowed = false`, so nothing is downloaded from iCloud. Same file, `fingerprint(of:pixelSize:)`;220  the fingerprint itself is in `ImageFingerprint.swift` (64-bit dHash, 64-bit pHash, mean luminance, 4 × 4 colour signature).221- **Persistent fingerprint cache.** `FingerprintCache` keys each fingerprint by asset identifier and modification222  date, so a re-scan only fingerprints new or changed assets. The file is versioned and checksummed; a corrupt or223  outdated file is discarded, and entries for assets that no longer exist are pruned. The cache is saved before a224  cancelled scan throws. `FingerprintCache.swift`, `PhotoLibraryScanner.swift`225- **Exact sizes and hashes only for candidates.** `PhotoSizeMeasurer` streams resource data (bytes counted and hashed226  in one pass) and is only asked about group members and the longest videos, not the whole library (test "Pipeline:227  only candidates are measured"). `PhotoSizeMeasurer.swift`, `MediaLibrary.swift`228- **Bounded grouping.** Visual similarity is evaluated inside capture sessions with a lookback limit, so work grows229  roughly linearly with the library; the cross-session global pass is off by default (`CleanupConfiguration.globalPassEnabled`).230  The performance test fails if 5× the items cost more than 15× the time. `CleanupAnalyzer.swift`231- **Streaming hashes.** `FileHasher.sha256` reads `chunkSize` bytes at a time (default 1 MiB, clamped to 4 KiB–16 MiB)232  inside an `autoreleasepool`, checks cancellation on every chunk and yields every 32 chunks.233  `Packages/ORIXFileInspection/Sources/ORIXFileInspection/FileHasher.swift`234- **Duplicate search without hashing everything.** Files are grouped by size, then by SHA-256 of the first 64 KiB, and235  only the remaining candidates are hashed in full. `DuplicateFinder.swift`236- **Bounded parsers.** Every parser reads untrusted bytes through `ByteSource` (bounded random access, overflow-safe237  integers). Limits live in `InspectionOptions`: 100 000 archive entries walked, 500 reported, raw scans limited to an238  8 MiB window at each end of the file, PDFKit not used above 256 MiB, 500 pages / 200 links for PDF links. Archives239  are never extracted or inflated. `ByteSource.swift`, `InspectionOptions.swift`, `ZipInspector.swift`, `TarGzipInspector.swift`240- **Bounded DER parsing.** The certificate parser stops at a nesting depth of 24 and 50 000 elements and throws typed241  errors. `Packages/ORIXNetworkLab/Sources/ORIXNetworkLab/DER.swift`242- **Bounded link analysis.** Evidence strings are clipped and the path scan is limited to its first 2 000 characters;243  a 300 000-character input is refused as unparsed in under 100 ms (test `longInputsAreBounded`).244  `Packages/ORIXURLRisk/Sources/ORIXURLRisk/URLRiskAnalyzer.swift`245- **Every network probe has a timeout.** TLS 10 s, DNS 5 s, TCP latency 3 s per attempt, HTTPS 10 s, path snapshot246  2 s by default; DNS lookups are limited to 4 at a time. `TLSInspector.swift`, `DNSProbe.swift`, `LatencyProbe.swift`,247  `HTTPSProbe.swift`, `ConnectivityMonitor.swift`248- **Cancellation everywhere.** Engines call `Task.checkCancellation()` / check `Task.isCancelled` (analyzer, scanner,249  measurer, hasher, folder walker, workflow runner), and the screens expose a Cancel control that cancels the task250  (`PhotoCleanupController.cancel`, `FileScannerView`, `FileCleanupView`, `ActionsController.cancel`).251- **No background work.** `App/Resources/Info.plist` declares no `UIBackgroundModes`, and the app sources contain no252  `BGTaskScheduler` or `beginBackgroundTask` call. Scans and probes run only while the user is looking at them.253- **No third-party code.** Every package dependency is a local path (`Scripts/check.sh` fails on a remote one), so254  there is no analytics, advertising or networking SDK adding launch time or background activity.255
Files main
Menu

Theme