Skip to content

improvement(serializer,3.x): cache requested (de-)serializations#53

Closed
brutal-factories wants to merge 4 commits intoliip:3.xfrom
brutal-factories:origin/improvement/avoid-file_exists-calls-3.x
Closed

improvement(serializer,3.x): cache requested (de-)serializations#53
brutal-factories wants to merge 4 commits intoliip:3.xfrom
brutal-factories:origin/improvement/avoid-file_exists-calls-3.x

Conversation

@brutal-factories
Copy link
Copy Markdown
Contributor

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets Same as #52, for 3.x
Documentation
License MIT

What's in this PR?

Improvement to Serializer's objectToArray and arrayToObject: cache all loaded (de-)serializers. This PR targets the 3.x, like #52 targets the 2.x

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix

Copy link
Copy Markdown
Member

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thanks for looking into this. did you measure the difference that the cache makes? because of require_once, i don't see that we would save much work with a cache.

Comment thread src/Serializer.php Outdated
throw UnsupportedTypeException::typeUnsupportedDeserialization($type);
}
require_once $filename;
// todo: index cache by function name instead of type when deserializing with groups/versions is supported
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you use the result of DeserializerGenerator::buildDeserializerFunctionName as cache key?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can, and the future of this function should be that, I took the shortcut when it seemed available, since without groups/versions, the function name will necessarily be a one-to-one with the type

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I ended up putting my timings on the 2.x version : #52 (comment)

Comment thread src/Serializer.php Outdated
}
require_once $filename;
// todo: index cache by function name instead of type when deserializing with groups/versions is supported
if (isset($this->cachedDeserializers[$type])) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i prefer array_key_exists - it is a bit more robust as e.g. isset would just return false instead of error if the cachedDeserializers property does not exist.

@dbu
Copy link
Copy Markdown
Member

dbu commented Apr 27, 2026

i merged the result of #52 into the 3.x branch, so this improvement is now in the newly released 3.3.0

@dbu dbu closed this Apr 27, 2026
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