TickerNotch is a Mac menu bar app that puts a live strip beside the MacBook notch: market tickers on one side, scrolling news headlines on the other. It runs all day, so whatever it costs, it costs for as long as the Mac is awake.


On 29 November I checked what it was costing on my own Mac. Five readings came back between 51.8% and 54.4% of one core (100% would be one core fully busy), and the process had accumulated 191 hours of CPU time since it was launched. That is far too much for a strip of text.

macOS had noticed too. On 17 November it had written a diagnostic report for version 1.10.1, which it does when an app uses too much processor for too long:

“"90 seconds cpu time over 167 seconds (54% cpu average), exceeding limit of 50% cpu over 180 seconds"

Those reports land in /Library/Logs/DiagnosticReports. It is a folder worth opening now and then if you ship a Mac app.

What I already knew

I had worked on this once before. In June the app sat at about 40% of one core, and a profile — a recording of where an app spends its time — showed the main thread busy with the behind-the-scenes work of figuring out which parts of the screen needed to be redrawn.

The scrolling rows are driven by an animation timer that, by default, redraws the screen 120 times a second. At the default scroll speed of 10 points per second, each update moved the row by about 0.083 points — and on a Retina display, one visible pixel is 0.5 points. So about five updates out of six were redoing the layout for a change nobody could actually see. I lowered the default rate to 60 updates a second and made the text only move in whole-pixel steps, so updates that land on the same pixel do no work at all.

That change was sound, and it is still in the app. But my own settings are heavier than the defaults: I run 120 updates a second, about 60 points per second, and 40 headlines in the news strip. At those settings, the row moves a full pixel on every single update, so there was nothing left for the pixel-snapping to skip. The new profile looked just like June's, with about 78% of the main thread's time still going into redraw work.

Three guesses

My first guess was the update rate again. I lowered it to see: 46.6% at 120 updates a second, 42.2% at 60, 35.0% at 30. Cutting the rate to a quarter removed only a quarter of the cost, so the update rate was not the main cause.

The second guess was that every single update rebuilt all the headlines from scratch. I wrote a test that runs the real scrolling row for a second and counts how often that happens. It came back clean, so that wasn't happening either.

The third was that the live price feed was flooding the strip with updates. I counted its messages, and there were only a handful in 30 seconds.

A line a second

So I stopped guessing and built a version of the app with counters in it. Once a second, it logged how often things were re-rendering: the view overall, the animation loop, and the individual headline cells.

The animation loop was ticking about 112 times a second, and the code that assembles the row's content was running about 225 times, but the headlines themselves weren't being rebuilt anywhere near that often. They were being rebuilt whenever the news strip as a whole refreshed — one to three times a second — because the strip is wired to the same data source as the price ticker, and that source republishes every second as prices change. Each of those refreshes rebuilt all 40 headlines three times over, and each one had its on-screen font rebuilt from scratch every time. That added up to between 120 and 360 headline rebuilds a second.

In other words: price updates were rebuilding the entire headline row, and the news strip never even displays a price.

Fix one: stop the wasted rebuilds

SwiftUI now checks whether anything about the headline row has changed (a headline, the typeface, the size, the speed or the width) and skips it if not. For Swift readers, the row is its own Equatable view. Fonts are cached. The row's builder runs once per render pass, where before it ran on every animation tick. Afterwards the counters showed zero headline cells rebuilt per second.

CPU went from about 30% to about 26.5%. It was a real saving, but most of the cost was still there.

Fix two: draw only what is on screen

I found the rest by changing one thing on that same build: how many headlines were in the strip. With 40 it read 28.3% and 24.8%. With five it read 11.7% and 10.8%, and with a single headline 10.3%.

Only two or three headlines are visible beside the notch at any moment, yet the cost followed the 40 that exist. Every headline was in the animated row, twice, and went through the render pass on every tick. The app was animating 40 headlines to show three.

Now each headline's width is measured once, when the headlines change. On each tick a small function works out which headlines overlap the visible strip, and only those are drawn. Scroll speed, pause on hover and clicking a headline to open it are unchanged, and in screenshots the old and new builds look the same.

Checking the fix

There are three new tests. Two of them host the real views in a window and let the animation run, and the third counts fonts. I ran each one with its fix deliberately broken, to prove it could fail. The animation tick test caught the content builder running 208 times in one second, where it allows fewer than 10. The test for unrelated data updates counted 6,060 rebuilt headline cells and expects none.

The font cache test taught me something. Its first version checked that two requests returned the same font object, and it passed with the cache switched off, because macOS hands back the same object for equal fonts whether you cache or not. I replaced it with a count of fonts built: 50 identical requests built 50 fonts without the cache and one with it. Breaking the fix on purpose is the only reason I caught that.

Before and after

I made Release builds of the unfixed code and of each fix, built and signed the same way, and ran them on my 2021 MacBook Pro (M1 Pro, 10 cores) on macOS 27 with my own settings. Each build was launched, given 14 seconds to settle, then measured for 40 seconds by reading the process's accumulated CPU time before and after. The Mac was busy with other work the whole time, so I alternated the builds over three rounds to spread that noise evenly. Figures are percent of one core.

Build

Round 1

Round 2

Round 3

Average

Unfixed

27.5%

31.0%

31.5%

30.0%

Fix one (no wasted rebuilds)

26.6%

27.2%

25.7%

26.5%

Fix two (only visible headlines drawn)

10.8%

10.5%

10.0%

10.4%

CPU before and after

That is 30.0% down to 10.4%, about 65% less CPU.

A note on reading these. The freshly launched benchmark builds read lower than the app that had been running for days (27 to 30% against the 46 to 54% from earlier that day), so I only compare numbers taken in the same alternating run. These are also my settings. I have not measured the defaults, which are lighter.

What is left

About 10% remains even with one headline in the strip. That is the animation loop itself, at about 112 ticks a second with the 120 fps setting, and it is the next thing I will work on.

Both fixes ship in the next TickerNotch update.

300+ apps for all your daily tasks.

Sign up to Setapp and try them for free.

Security-tested