Skip to content

Conversation

@ashb
Copy link
Member

@ashb ashb commented Dec 9, 2025

The main problem here was that importing pendulum.testing.traveller was
importing time_machine, which was also importing pytest.

And creating the DifferenceFormatter at import time was also loading the
locale.

Both of these are "optional" in the sense that there is lots you can do in
Pendulum without ever using them, so we can relatively straightforwardly delay
things until they are requested.

Tested by running uv run --with time_machine -p 3.12 python -Ximporttime -c 'import pendulum':

  • Before: ~50-64ms (a lot of noise)
  • After: 20-29ms

Not a huge slow down, but I figured it was worth it anyway, especially not not
load pytest.

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 9, 2025

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing lazyload-or-lazy-create (0634927) with master (2982f25)

Summary

✅ 1 untouched benchmark

@ashb ashb force-pushed the lazyload-or-lazy-create branch 3 times, most recently from bc7ebbe to a852f8c Compare December 11, 2025 11:04
The main problem here was that importing pendulum.testing.traveller was
importing time_machine, which was also importing pytest.

And creating the DifferenceFormatter at import time was also loading the
locale.

Both of these are "optional" in the sense that there is lots you can do in
Pendulum without ever using them, so we can relatively straightforwardly delay
things until they are requested.

Tested by running `uv run --with time_machine -p 3.12 python -Ximporttime -c 'import pendulum'`:

- Before: ~50-64ms (a lot of noise)
- After: 20-29ms

Not a huge slow down, but I figured it was worth it anyway, especially not not
load pytest.
@ashb ashb force-pushed the lazyload-or-lazy-create branch from a852f8c to 0634927 Compare January 9, 2026 20:25
@Secrus Secrus merged commit 5cd742f into master Jan 10, 2026
21 checks passed
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.

3 participants