Skip to content

Conversation

@baxeaz
Copy link
Contributor

@baxeaz baxeaz commented Jul 4, 2025

What was the problem/requirement? (What/Why)

Recent changes to type validation have created a performance bottleneck with larger templates in pydantic's TypeAdapter.

What was the solution? (How)

What is the impact of this change?

~87% performance improvement when testing with larger templates

How was this change tested?

  • All unit tests passed
  • New benchmark test added which showed a ~87% performance improvement with vs without the cache.
  • End to End testing performed in deadline cloud with the patch applied showed the fix resolved the failing test which originally uncovered the performance issue

Was this change documented?

Yes

Is this a breaking change?

No

Does this change impact security?

No


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@baxeaz baxeaz requested a review from a team as a code owner July 4, 2025 16:16
crowecawcaw
crowecawcaw previously approved these changes Jul 7, 2025
mwiebe
mwiebe previously approved these changes Jul 7, 2025
A TypeAdapter for the given type.
"""
# Use the string representation of the type as a cache key
type_key = str(field_type)
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try id as an alternative to str as well? If types aren't too redundant, it might be a bit faster.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was indeed an improvement! I had some concerns about how those ids would resolve/collide but after doing a bit more investigation/testing looks like this is the way to go. Thanks!

Comment on lines +93 to +96
# Verify that the operation completed within a reasonable time
assert (
elapsed_time < 10
), f"Operation took {elapsed_time:.2f} seconds, which exceeds the 10 second threshold"
Copy link
Contributor

Choose a reason for hiding this comment

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

How close are we to this threshold?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's going to depend on the host which is part of why I've relegated it to "benchmark", but I'm running it in about 4 seconds currently

sync = "pip install -r requirements-testing.txt"
test = "pytest --cov-config pyproject.toml {args:test}"
test = "pytest test/ --cov-config pyproject.toml --ignore=test/openjd/model/benchmark {args}"
benchmark = "pytest test/openjd/model/benchmark --no-cov {args}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be running these in GitHub actions to prevent regression before merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was looking at that - I'd like to, but it looks like the commands run live in a shared config currently. If there's a simple way to add that I'm happy to do it though!

@baxeaz baxeaz dismissed stale reviews from mwiebe and crowecawcaw via 6b09ccb July 7, 2025 21:03
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 7, 2025

@baxeaz baxeaz merged commit b62a4f1 into OpenJobDescription:mainline Jul 7, 2025
19 checks passed
miabatta pushed a commit to miabatta/openjd-model-for-python that referenced this pull request Sep 9, 2025
OpenJobDescription#212)

fix: Adding a TypeAdapter cache to fix a performance regression with larger templates.

Signed-off-by: Brian Axelson <[email protected]>
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.

4 participants