Use cached zmanim.LoadLocation - #11
Merged
Merged
Conversation
Bump hebcal-go to v0.17.1 and route the tzid lookups in location.go, shabbat.go and zmanim.go through the new caching zmanim.LoadLocation instead of time.LoadLocation. time.LoadLocation re-parses the tzdata database on every call (~10us and several KB of garbage per lookup); these paths repeatedly load the same handful of zones (pos-location validation, and the Expires/date helpers on every /zmanim and /shabbat request), so the cache turns them into ~20ns pointer loads. The one-time America/New_York load in main.go is left as-is: its result is stored in the nyLoc global and reused directly, so it never re-loads. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SnNqQE8n9SckYpeaHgcWsV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to hebcal/hebcal-go#34 (released as v0.17.1).
time.LoadLocationre-parses the tzdata database on every call (~10 µs and several KB of garbage for a typical zone) and does not cache internally. This service loads the same handful of timezones repeatedly:location.go— pos-location tzid validation (the loaded*time.Locationwas discarded; it's purely a validity check)shabbat.go— the Shabbat-week date range and the Saturday-nightExpiresheader, on every/shabbatrequestzmanim.go— theLast-Modified/Expireshelpers andnowInTimezone, on every/zmanimrequestChange
hebcal-gov0.17.0 → v0.17.1.zmanim.LoadLocation. Cached hits drop from ~10 µs / ~8 KB to ~20 ns / 0 allocs.The one-time
America/New_Yorkload inmain.gois intentionally left ontime.LoadLocation: its result is stored in thenyLocglobal and reused directly, so it never re-loads and gains nothing from the cache.Note that v0.17.1 also caches the
time.LoadLocationinsidezmanim.Newitself — the biggest lever, since a multi-day/zmanimrange was previously re-parsing the same zone once per day. This PR covers the remaining call sites in the service.Verification
gofmt -l,go vet -tags sqlite_fts5 ./...,go build -tags sqlite_fts5, and the fullgo test -tags sqlite_fts5 -race ./...all pass (the existing/zmanim,/shabbat, and/geopos tests exercise the changed paths).🤖 Generated with Claude Code
https://claude.ai/code/session_01SnNqQE8n9SckYpeaHgcWsV
Generated by Claude Code