Menu

From a polling Bash script to an event-driven Swift daemon on macOS
πŸ“°

From a polling Bash script to an event-driven Swift daemon on macOS

DEV Community: swiftΒ·Mike VuΒ·9 days ago
#AslEIWv6
#devtoswift#devto#dev#daemon#polling
Long article (1551 words) β€” no AI summary yet.
Reading 0:00
15s threshold

The first version of MacSentry 's root daemon was a 1,110-line Bash script that polled the system in a loop. It worked, but on my Apple M4 development Mac it was measured at about 10% of one core at one point, and even after two rounds of optimization it still used about 4.5%, all day. The Swift rewrite runs at about 0.4%. This post covers what actually made the difference: forks, polling, cheap change detection, letting macOS deprioritize the daemon, and an undocumented netstat behavior that silently hides connections.

The numbers come from the commit history and were measured on that one machine.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.