Skip to content

perf(bb-cron-job): reuse the timezone formatter during cron search - #1659

Open
ikenyal wants to merge 1 commit into
aws:mainfrom
ikenyal:perf/cron-timezone-formatter
Open

ikenyal wants to merge 1 commit into
aws:mainfrom
ikenyal:perf/cron-timezone-formatter

Conversation

@ikenyal

@ikenyal ikenyal commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Problem

The local CronJob mock creates a new Intl.DateTimeFormat for every minute it checks when searching for the next occurrence in a time zone. This adds synchronous startup work for sparse schedules even though all candidates use the same formatter options.

Issue #, if available: N/A

Changes

  • Create one formatter per time-zone-aware search and reuse it for all candidate minutes. Keep the UTC path unchanged when no time zone is configured.
  • Preserve the search window, schedule matching, and timer behavior. Document the implementation and add a patch changeset.

Validation

  • The new fake-clock regression fails on main because a single weekly search constructs a formatter for each candidate minute. With the fix it constructs one, and the job still fires at the expected instant. A second test checks that jobs in Tokyo and Kolkata use their own time zones.
  • In one local Node 22 measurement, constructing a monthly Asia/Tokyo job just after its January occurrence took about 1.16 seconds on main and 0.09 seconds with this change. Both builds selected the same February occurrence. The regression test checks formatter allocations and scheduled times, not wall-clock latency.
  • IS_WEBPACK_TEST=1 npm run build, npm run lint, npm run lint:deps, npm test -w @aws-blocks/bb-cron-job, npm run check:api, and changeset guards.
  • Workspace unit tests, including isolated reruns for tests sensitive to temporary-directory placement or concurrent dev-server startup.
  • npm run test:e2e:local and git diff --check origin/main...HEAD.

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ikenyal
ikenyal requested a review from a team as a code owner November 19, 2026 05:58

This branch has not been deployed

No deployments
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.

1 participant