r/iOSProgramming • u/Raalders • Aug 08 '26
App Saturday Shipped my Tokyo transit app: ~3000 live vehicles on MapKit in SwiftUI. Some things that didn't work
Launched Tokyo Glance on Sunday. It's a live map of Tokyo: all the tracked trains, buses and planes moving in real time, plus departure boards, a widget, and a Live Activity that follows your train from the lock screen.
Stack: SwiftUI on iOS 26 with the native SwiftUI Map (started on MKMapView with a UIViewRepresentable, ripped it out mid-project). The vehicles are not MapKit annotations, I draw them myself in an overlay pass. I tried making them proper annotations at some point because it felt like the "right" way and at ~1400 vehicles it performed so much worse than my own drawing that I never looked back. There's a small Metal layer for rain on the map. Alerts from the operators are almost always Japanese-only so they get translated on-device with the Translation framework. Paywall is RevenueCat, widget is WidgetKit + AppIntents, pushes for the Live Activity go through FCM.
Backend is Bun + Hono + MongoDB + Zod and nothing else. It runs in tiny containers behind Cloudflare so basically everything is precomputed and CDN-cached, the containers can't afford real per-request work. A separate ingestion service pulls the operator feeds (ODPT, GTFS-RT), snaps positions onto the actual track geometry and rebuilds the whole network dataset every night. The phone mostly just interpolates between feed ticks. Every time I moved logic out of the app into the pipeline things got faster.
One thing I didn't appreciate before this project: how much you get from Apple for free. MapKit on native apps is unlimited, and that includes the photorealistic 3D city rendering and Look Around imagery, which would cost real money on any other map provider at this usage. WeatherKit comes with 500k calls a month with the dev membership, I cache the Tokyo weather grid on the backend so users share it and I don't even get close to the cap. The Translation framework is free and on-device, which is the only reason "every service alert translated to English" is economically possible at all, per-call translation APIs would eat the entire subscription margin. Same with the on-device Foundation Models, small copy generation costs literally nothing. A one-person app like this basically doesn't work financially on other stacks.
Stuff I built and then deleted:
The station orbit camera. Killed it twice. A slow orbit around a station, how hard can it be. My optimized attempts (shared display link, coarser ticks) used 168-200% CPU and looked worse than the naive per-frame version. For reference, Apple's own realistic 3D city mode sits at ~130% CPU if you park the camera in Shinjuku. There is no orbit in the shipped app.
3D landmark models. Tokyo's open PLATEAU dataset only goes to LOD2, all of Tokyo Tower shares a single 512x512 texture. Looked terrible, cut the feature. Can't code your way around source data.
Also fun: Japanese timetables represent post-midnight departures as "00:26" or "24:26" depending on the operator, sometimes both in one feed. First time I've seen a 24+ hour clock in production data. Got that wrong more than once before normalizing it in one place at ingestion.
And I lost a few days to a paywall crash that only happened on Macs. Looked exactly like a RevenueCat bug. It was SwiftUI dropping environment values across the sheet bridge when the iPad build runs on macOS.
Money stuff since the rules ask: free app, subscription for the deeper features (lock screen follow, time travel replay).
AI disclosure: this app is majorly AI-written, no way around it. The backend is ~99% Claude Code with me doing specs and PR review. The SwiftUI app I'm more hands-on with, but AI still wrote most of the code there too — my job was deciding what to build, reviewing everything, and testing on device until it felt right. This post was drafted with AI as well.
App Store: https://apps.apple.com/app/id6782602634
7
u/ThatGuy739 Aug 08 '26
The "how much you get from Apple for free" point is the one I would underline hardest, and I agree it changes what one person can ship. Worth adding the catch though, because it caught me: those frameworks are free per call, but they are not free in concurrency, and that is where the real ceiling sits.
On a server you scale media work by adding workers. On device you are sharing a small pool of hardware backed sessions with the rest of the system, and when you oversubscribe them you do not get a queue and you do not get a clean error. I had concurrent decodes off the same composition hang the device outright. The same pattern on macOS wedges the VideoToolbox XPC services until you go and kill them. Worst part is the signature before it gets that far: EXC_BAD_ACCESS deep inside copyNextSampleBuffer, which sends you hunting for a memory bug that does not exist. The actual fix was boring, a gate that serializes session setup so only one reader is ever starting up at a time.
So the model I landed on is that on device gives you unlimited volume but fixed width. Your instinct to push everything into the nightly pipeline works partly for that reason, it moves work off the narrow path entirely. For anything you cannot precompute, it pays to funnel it through one owner of the concurrency rather than letting call sites fan out just because the work looks embarrassingly parallel.
Also agreed on Translation being the thing that makes per alert English viable at all. Per call pricing turns that from a feature into a line item.
4
u/RIRLift Aug 08 '26
Makes sense that self-drawing won. Each MKAnnotationView is a real UIView, so past a few hundred you're paying layout and compositing per vehicle every time the region changes, and MapKit recycles them badly when everything is moving at once. One overlay pass collapses all of that into a single redraw, which is why the naive version beat the "proper" one. How are you handling hit testing on the custom vehicles though? That's usually what you give up when you drop annotations, so I'm curious whether tapping a train to select it still works.
2
u/Otherwise_Signal7274 Aug 08 '26
> Also fun: Japanese timetables represent post-midnight departures as "00:26" or "24:26" depending on the operator, sometimes both in one feed. First time I've seen a 24+ hour clock in production data. Got that wrong more than once before normalizing it in one place at ingestion.
it’s probably because it’s presented like that in gtfs spec https://gtfs.org/documentation/schedule/reference/#stop_timestxt
2
u/Plastic-Risk-6309 Aug 08 '26
The MapKit annotation finding matches what I've seen: MKAnnotationView is fine for tens of things and falls apart in the hundreds because you're paying UIKit view lifecycle per vehicle, and reuse doesn't save you when nearly all of them move every tick. Drawing into one overlay pass is the right answer at ~1400, and you get to keep a single coordinate transform instead of fighting per-view placement during zoom.
The part I'd steal is the ingestion service rebuilding geometry once and the phone interpolating between ticks. That's the difference between a live map and a battery experiment, and it's the thing people usually discover only after shipping.
On the free 3D imagery: worth noting the cost isn't purely per call, it's also that photorealistic rendering pushes sustained GPU work, which shows up as thermals on older devices before it shows up on your bill. Your 130% CPU number for parking the camera in Shinjuku is a useful data point, it's roughly "one core permanently busy so a user can look at a building".
Curious how you're testing the vehicle layer at that density. Live feeds make regression testing painful, and a recorded tick stream you can replay deterministically is the only thing I've found that makes performance work measurable rather than vibes.
2
u/alanrick Aug 08 '26
Maybe I’m the exception. But I’m happy you used AI to draft the post. It’s easy for me to read. Just sayin.
2
u/phunk8 Aug 09 '26
thank you for the great read! both op and that guy