Skip to content

Use cached zmanim.LoadLocation - #11

Merged
mjradwin merged 1 commit into
mainfrom
claude/cache-loadlocation
Jul 9, 2026
Merged

Use cached zmanim.LoadLocation#11
mjradwin merged 1 commit into
mainfrom
claude/cache-loadlocation

Conversation

@mjradwin

@mjradwin mjradwin commented Jul 9, 2026

Copy link
Copy Markdown
Member

Follow-up to hebcal/hebcal-go#34 (released as v0.17.1).

time.LoadLocation re-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.Location was discarded; it's purely a validity check)
  • shabbat.go — the Shabbat-week date range and the Saturday-night Expires header, on every /shabbat request
  • zmanim.go — the Last-Modified/Expires helpers and nowInTimezone, on every /zmanim request

Change

  • Bump hebcal-go v0.17.0 → v0.17.1.
  • Route those 7 call sites through the new caching zmanim.LoadLocation. Cached hits drop from ~10 µs / ~8 KB to ~20 ns / 0 allocs.

The one-time America/New_York load in main.go is intentionally left on time.LoadLocation: its result is stored in the nyLoc global and reused directly, so it never re-loads and gains nothing from the cache.

Note that v0.17.1 also caches the time.LoadLocation inside zmanim.New itself — the biggest lever, since a multi-day /zmanim range 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 full go test -tags sqlite_fts5 -race ./... all pass (the existing /zmanim, /shabbat, and /geo pos tests exercise the changed paths).

🤖 Generated with Claude Code

https://claude.ai/code/session_01SnNqQE8n9SckYpeaHgcWsV


Generated by Claude Code

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
@mjradwin
mjradwin merged commit 08b6eed into main Jul 9, 2026
2 checks passed
@mjradwin
mjradwin deleted the claude/cache-loadlocation branch July 9, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants