Hackfetch Is Now Actually Fast
Last log I added a loading spinner so you’d have something to look at while hackfetch was hitting the Hackatime API. This week I made it so you barely have time to see the spinner at all (undoing all my work lol)
The problem
hackfetch was making four separate calls to Hackatime for every fetch:
/users/current/heartbeats/most_recent (for your slack handle)
/users/current/summaries (for your streak)
/users/current/statusbar/today (for today's coding time)
/users/current/stats/last_7_days (for weekly stats)
Doing them one after another meant the total wait was the sum of all four. Turns out that’s about 1.7 seconds on a normal connection. Not the end of the world, but very noticeable when you just want to open a terminal.
The fix: run them all at the same time
Now hackfetch fires all four calls in parallel using goroutines, waits for the slowest one to come back, and then builds the fetch from the responses. Total wait drops from “sum of all four” to “just the slowest one.”
- Before: ~1.7 seconds
- After: ~0.7 seconds
60% faster. Every single fetch. Every single time.
One tiny bonus optimization
While I was in there, I also switched to a single shared HTTP client with a bigger connection pool. The default Go setup caps you at 2 open connections per host, which is fine when you’re calling one endpoint at a time but hurts when you’re firing four at once. Now the parallel calls can share connections instead of stacking up on each other.
Nothing about the fetch itself changed. Same info, same layout, same colors. Just faster.
Ship
Shipped in v1.7.2. If you have hackfetch installed:
brew update
brew upgrade hackfetch
time hackfetch
Watch the spinner barely have time to appear.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.