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 #926 will not alter performance

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

Summary

✅ 1 untouched

@ashb ashb force-pushed the lazyload-or-lazy-create branch 2 times, most recently from 6b86f50 to bc7ebbe Compare December 11, 2025 10:06
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 bc7ebbe to a852f8c Compare December 11, 2025 11:04
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