⚡ Bolt: Cache Foundation formatters to improve UI and scanning performance#160
⚡ Bolt: Cache Foundation formatters to improve UI and scanning performance#160
Conversation
Centralized shared Foundation formatters (ByteCountFormatter and ISO8601DateFormatter) in a shared model/enum (Formatters) to avoid performance overhead from repeated instantiations in high-frequency methods. Co-authored-by: acebytes <2820910+acebytes@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e96ecbefd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import Foundation | ||
|
|
||
| enum Formatters { | ||
| static let byteCount: ByteCountFormatter = { |
There was a problem hiding this comment.
Avoid sharing non-Sendable formatter singletons
The new Formatters globals introduce shared ByteCountFormatter/ISO8601DateFormatter instances that are accessed from different isolation domains (for example @MainActor view-model formatting and CacheCleaner actor logging). Both formatter classes are mutable and non-Sendable, so this pattern creates cross-actor shared state that can race at runtime and is flagged by Swift concurrency diagnostics (MutableGlobalVariable, which becomes an error in Swift 6 mode). Prefer actor-local formatters or isolate these globals to a single global actor.
Useful? React with 👍 / 👎.
💡 What
Created a centralized
Formattersenum to lazily initialize and store shared instances ofByteCountFormatterandISO8601DateFormatter. Replaced all repetitive ad-hoc instantiations across the codebase with references to these shared instances.🎯 Why
Instantiating Foundation formatters (
DateFormatter,ISO8601DateFormatter,ByteCountFormatter) is a known, computationally expensive operation in Swift. Repeatedly instantiating them inside rendering loops (like SwiftUI views or list builders) and high-frequency scan parsing methods introduces unnecessary allocation overhead, impacting smooth scrolling and the execution time of cache scanning.📊 Impact
scanResultslist and Quick Stats indicators.🔬 Measurement
Verify the changes by compiling the application and observing UI performance on the
CleanConfirmationmodal and mainCacheoutViewModelresults page. Ensure the reported sizes match expected formatting. Runningcacheout --cli scanwill also exhibit fractionally faster parsing/output due to reused formatting during disk sweeps.PR created automatically by Jules for task 16235758208118321414 started by @acebytes