Skip to content

Round the next fetch dates without a Calendar - #2290

Merged
rzo1 merged 1 commit into
mainfrom
faster-date-rounding
Oct 30, 2026
Merged

rzo1 merged 1 commit into
mainfrom
faster-date-rounding

Conversation

@jnioche

@jnioche jnioche commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

AbstractStatusUpdaterBolt.execute() rounds the next fetch date with DateUtils.round, which builds a GregorianCalendar for every URL. When profiling the status updater with StatusUpdaterBenchmark going through execute(), this was the largest share of the CPU used by the bolt threads, about a third of it, more than the cache or the filtering of the metadata.

Rounding to the second or the minute is now done on the epoch time, half up, which gives the same dates as DateUtils. A quick timing gives about 230 ns per call with DateUtils and a few ns without it. Rounding to the hour depends on the time zone, e.g. with an offset of 5:30, so it still goes through DateUtils.

The tests compare the new rounding with DateUtils on edge values and on 100,000 random dates. They pass with UTC, Asia/Kolkata, America/St_Johns, Asia/Kathmandu, Europe/Paris, America/New_York and Australia/Lord_Howe as default time zone.

While testing, I found that DateUtils can move a date in the hour repeated when the clocks go back to the other occurrence of that hour. In Paris, 02:22:47 CEST is rounded to the minute as 02:23 CET, an hour later. The new rounding keeps it at 02:23 CEST, a test covers this case.

🤖 Generated with Claude Code

DateUtils.round builds a GregorianCalendar for every URL, which was the
largest share of the CPU used by AbstractStatusUpdaterBolt.execute().
Rounding to the second or minute is now done on the epoch time, half up,
which gives the same dates as DateUtils. Rounding to the hour depends on
the time zone and still goes through DateUtils.

DateUtils can also move a date in the hour repeated when the clocks go
back to its other occurrence, an hour away. The new rounding keeps it
where it is.

Signed-off-by: Julien Nioche <julien@digitalpebble.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jnioche jnioche added this to the 4.0.0 milestone Oct 30, 2026
@rzo1
rzo1 merged commit 9ea2348 into main Oct 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants