Skip to main content

Posts

Showing posts with the label macOS

Optimizing SwiftUI `Table` Performance for 50,000+ Row Data Grids on macOS

  You have built a native macOS utility using SwiftUI. It looks modern, the code is clean, and it handles test data beautifully. Then you load a real-world dataset—50,000 rows of log entries or financial records—and the application falls apart. Scrolling stutters, the CPU spikes to 100%, and sorting the columns freezes the UI for several seconds. While the older AppKit  NSTableView  handles millions of rows effortlessly using cell recycling and delegation, SwiftUI’s declarative nature introduces a "Diffing Tax" that can cripple performance if not managed correctly. This guide details exactly why SwiftUI  Table  chokes on large datasets and provides a production-ready architectural pattern to render 50k+ rows at 60 FPS. The Root Cause: The SwiftUI Diffing Tax To fix the lag, you must understand what SwiftUI is doing during a render pass. When you pass an array of 50,000 items to a SwiftUI  Table , the framework must determine what changed since the last fram...

macOS Menu Bar Apps: SwiftUI Popovers and WindowManagement APIs

  Building a "Status Bar Only" application (agent app) on macOS seems deceptively simple: set a flag in   Info.plist , use a   MenuBarExtra , and you are done. However, as soon as you attempt to add complex interactivity—text inputs, intricate state management, or custom window sizing—the abstraction leaks. You encounter the classic "Agent App" lifecycle problems: The popover doesn't automatically close when clicking the desktop. Text fields refuse to accept focus because the app never officially "activates." MenuBarExtra  in  .window  style lacks fine-grained control over positioning relative to the screen edge. To build a production-grade utility that feels like native macOS Control Center modules, we must bypass the  MenuBarExtra  wrapper and orchestrate  NSStatusItem ,  NSPopover , and the  NSApplication  activation policy manually. The Root Cause: Application Activation Policy The core issue lies in how macOS treats applic...