-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Optimize TypeRegistry::lookupName() from O(N) to O(1) #6082
Optimize TypeRegistry::lookupName() from O(N) to O(1) #6082
Conversation
5029656
to
a5e6e82
Compare
a5e6e82
to
7f3c2bc
Compare
7f3c2bc
to
71f1411
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this a performance improvement and not a bugfix, let's target 3.7.x.
71f1411
to
92a3c40
Compare
Is there any chance this can go into 3.6.x? We use lookups heavily, thus for us the O(N) performance is a "bug". |
b3b09ad
to
ccfe3e6
Compare
No. |
ccfe3e6
to
33be3f8
Compare
33be3f8
to
430c9ae
Compare
Thank you for this very nice improvement, @mvorisek! |
* 3.7.x: Optimize TypeRegistry::lookupName() from O(N) to O(1) (doctrine#6082) Add documentation for doctrine#6044 (doctrine#6069) Use triggerIfCalledFromOutside in listTableDetails Document alternative to Type::getName (doctrine#6077)
* 3.7.x: Optimize TypeRegistry::lookupName() from O(N) to O(1) (doctrine#6082) Add documentation for doctrine#6044 (doctrine#6069) Use triggerIfCalledFromOutside in listTableDetails Document alternative to Type::getName (doctrine#6077)
* 3.7.x: Avoid self deprecation about listTableColumn (doctrine#6108) Fix blob binding overwrite on DB2 (doctrine#6093) Optimize TypeRegistry::lookupName() from O(N) to O(1) (doctrine#6082) Add documentation for doctrine#6044 (doctrine#6069) Use triggerIfCalledFromOutside in listTableDetails Document alternative to Type::getName (doctrine#6077)
| Q | A |------------- | ----------- | Type | feature | Fixed issues | n/a #### Summary `Type` class has static methods for global `TypeRegistry` instance shorter access like `Type::getType`. This feature adds a static method for `TypeRegistry::lookupName`. Thanks to #6082, the reverse lookup is O(1) thus fine to be used massively - for ex. schema introspection returns type as object, and this method is needed to obtain a string name. In DBAL 4.0, the method can be renamed to `Type::getName(Type $type): string` to be more consistent with `Type::getType(string $name): Type`.
| Q | A |------------- | ----------- | Type | performance issue | Fixed issues | n/a #### Summary We use a lot of custom types and migration from `Type::getName()` to `TypeRegistry->lookupName()` discovered us the reverse lookup was very slow (O(N)). This PR makes it O(1). ~Index is initialized lazily on the 1st reverse lookup.~ The type registry is expected to not hold duplicate type instances and this PR fixes it, in doctrine#6083 (comment) I was requested to fix it in this PR instead of a separate one.
| Q | A |------------- | ----------- | Type | feature | Fixed issues | n/a #### Summary `Type` class has static methods for global `TypeRegistry` instance shorter access like `Type::getType`. This feature adds a static method for `TypeRegistry::lookupName`. Thanks to doctrine#6082, the reverse lookup is O(1) thus fine to be used massively - for ex. schema introspection returns type as object, and this method is needed to obtain a string name. In DBAL 4.0, the method can be renamed to `Type::getName(Type $type): string` to be more consistent with `Type::getType(string $name): Type`.
Summary
We use a lot of custom types and migration from
Type::getName()
toTypeRegistry->lookupName()
discovered us the reverse lookup was very slow (O(N)). This PR makes it O(1).Index is initialized lazily on the 1st reverse lookup.The type registry is expected to not hold duplicate type instances and this PR fixes it, in #6083 (comment) I was requested to fix it in this PR instead of a separate one.