Skip to content

Conversation

@iloveitaly
Copy link
Contributor

No description provided.

@nateprewitt
Copy link
Contributor

Hi @iloveitaly, thanks for PR! If you don't mind, I'm going to add a couple more commits onto this to help get some other versioning changes finished. Then we'll be able to get your contribution shipped.

@nateprewitt nateprewitt requested a review from jamesls July 18, 2025 16:41
@nateprewitt nateprewitt force-pushed the patch-1 branch 3 times, most recently from a55d929 to 73c5404 Compare July 18, 2025 18:45
@nateprewitt nateprewitt changed the title ci: py 3.12 + 3.12 test runs ci: Add support for testing Python 3.12-3.14 Jul 18, 2025

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- uses: actions/checkout@v4
- uses: actions/checkout@v5

Copy link
Member

@jamesls jamesls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to split out the testing related changes for new python versions from the caching issue? Or was there a specific reason we need this included with this PR?

def _free_cache_entries(self):
for key in random.sample(list(self._CACHE.keys()), int(self._MAX_SIZE / 2)):
self._CACHE.pop(key, None)
with self._CACHE_LOCK:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind me again, why do we need a lock here, what issue are addressing? Is it #334? I'd prefer addressing this without adding a lock.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is slightly different than #334 but the same underlying flaw. We sample our cache to do eviction which can already be in the process of being freed. If you run the existing test suite with Python 3.11+, you'll see test_thread_safety_of_cache fails for all versions.

We eagerly call _free_cache_entries every parse() invocation which puts this on the hot path. What makes it particularly noticeable though is our max cache size/eviction logic don't work how I think they were intended.

When we pop keys, we always remove a random sample of self._MAX_SIZE/2 (64) entries. The problem is we have no upper bound on the cache size, so it's possible to have cases where we have significantly more than 128 entries and a free may not bring us under the cache limit. That means multiple calls can trigger a free because we didn't do it properly the first attempt exacerbating the issue.

Happy to look at non-locking options but what would your high-level thought be there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened #335 for more targeted discussion. I'll pull the cache changes out of this, we just won't be able to merge until the underlying issue is fixed in the test suite.

Copy link
Contributor

@nateprewitt nateprewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I think we're ready to merge this with #335 in place. @hugovk I'm going to move the workflow tags to explicit pins in a follow up PR so we'll take care of that there. This should get us unblocked for a new release with Python 3.12-14 support.

@nateprewitt nateprewitt merged commit f06ac6a into jmespath:develop Dec 10, 2025
6 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.

5 participants