Faster sunrise, sunset, and twilight searches

Almanac 0.4.2

Release Sky

Almanac 0.4.2 speeds up Sun and Moon rise, set, and twilight searches in TypeScript and Swift, and the Sun's position in TypeScript. The public API is unchanged.

  • Event searches find altitude extrema with Brent's method instead of a fixed 22-sample golden section, and find altitude crossings with a cosine-seeded secant solver. Every crossing is still proven inside a half-second bracket, and anything that stalls or leaves the segment falls back to the bracketed search. Sampler calls for a year at Victoria drop from 40,681 to 15,400 for Sun events and from 24,437 to 10,173 for Moon events.
  • The TypeScript Sun series evaluates its 51 VSOP87 terms as straight-line arithmetic rather than iterating the coefficient table, for bit-for-bit identical results. Swift already evaluated the series efficiently and mirrors the structure for the twin-port contract.

The focused year benchmark returns the same 3,255 Sun events:

Port v0.4.1 v0.4.2 Change
TypeScript 136.267 ms 36.268 ms 73.4% faster
Swift 56.322 ms 20.963 ms 62.8% faster

Moon events over the same year are 57.6% faster in TypeScript and 57.4% faster in Swift. Sun positions, the sky track, Moon phases, and every lunar and solar eclipse workload are 21% to 36% faster in TypeScript; Swift's remaining workloads are within 2%.

Each search now reports the root inside its verified bracket rather than the bracket's midpoint, so event times move by at most a third of a second. Across 1950 through 2100 at Victoria, 60°N, the equator, and 70.5°S, every event count, kind, and order is identical, and the parity corpus still holds 9,449 Sun events and 2,115 Moon events.

npm install @openwaters/almanac@0.4.2
.package(url: "https://github.com/openwatersio/almanac.git", exact: "0.4.2")

Sun series: #32. Event searches: #34.

Full changelog.