Skip to content

⚡ Bolt: Cache Foundation formatters to improve UI and scanning performance#160

Open
acebytes wants to merge 1 commit intomainfrom
bolt/formatter-allocations-16235758208118321414
Open

⚡ Bolt: Cache Foundation formatters to improve UI and scanning performance#160
acebytes wants to merge 1 commit intomainfrom
bolt/formatter-allocations-16235758208118321414

Conversation

@acebytes
Copy link
Copy Markdown
Contributor

💡 What
Created a centralized Formatters enum to lazily initialize and store shared instances of ByteCountFormatter and ISO8601DateFormatter. 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

  • Eliminates repeated memory allocations for formatters across standard UI components, CLI rendering, and backend JSON tagging.
  • Accelerates the UI update cycle by reusing formatters for the scanResults list and Quick Stats indicators.
  • Removes garbage collection/ARC overhead for short-lived formatters during batch processing operations.

🔬 Measurement
Verify the changes by compiling the application and observing UI performance on the CleanConfirmation modal and main CacheoutViewModel results page. Ensure the reported sizes match expected formatting. Running cacheout --cli scan will also exhibit fractionally faster parsing/output due to reused formatting during disk sweeps.


PR created automatically by Jules for task 16235758208118321414 started by @acebytes

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>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant