Skip to content

feat(#4218): avoid executing the injection logic multiple times #5201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from

Conversation

giulong
Copy link
Contributor

@giulong giulong commented Jun 20, 2025

Given there are multiple entry points for injection (creator properties vs fields and setters), would a cache in DeserializationContext be good to avoid executing the injection logic multiple times? Is the tradeoff of having a bit more space consumption vs much lower (I guess) execution time performance worth it?

Especially considering that every new feature added in the @JacksonInject context, without a cache would mean duplicating the logic in a slightly different way, since creator properties and fields injection are managed differently.

Comment on lines +495 to +507

Object value = _injectablesCache.get(valueId);

if (value == null) {
value = _injectableValues.findInjectableValue(this, valueId, forProperty, beanInstance,
optional);

if (value != null) {
_injectablesCache.put(valueId, value);
}
}

return value;
Copy link
Member

Choose a reason for hiding this comment

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

Would this make injectino logic to run exactly once? Or less than before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly once, as proven by this test, which doesn't fail anymore with the change above

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