-
-
Notifications
You must be signed in to change notification settings - Fork 502
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
Improved performance of Uuid::fromString()
, Uuid::fromBytes()
, UuidInterface#toString()
, UuidInterface#getBytes()
#324
Improved performance of Uuid::fromString()
, Uuid::fromBytes()
, UuidInterface#toString()
, UuidInterface#getBytes()
#324
Conversation
Here are some preliminary results: Before the patch (79589a2)
First optimization of
|
Uuid::fromString()
, Uuid::fromBytes()
, Uuid#toString()
, Uuid#getBytes()
Uuid::fromString()
, Uuid::fromBytes()
, Uuid#toString()
, Uuid#getBytes()
@@ -1431,7 +1428,6 @@ public function providePythonTests(): array | |||
'clock_seq' => '27b8', | |||
'variant' => Uuid::RFC_4122, | |||
'version' => Uuid::UUID_TYPE_HASH_MD5, | |||
'class' => UuidV3::class, |
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.
Note: I don't think that changing the type of Uuid::fromString()
is a BC break here, since the interfaced type is still respected
Uuid::fromString()
, Uuid::fromBytes()
, Uuid#toString()
, Uuid#getBytes()
Uuid::fromString()
, Uuid::fromBytes()
, UuidInterface#toString()
, UuidInterface#getBytes()
Obviously, all of this is easily subject to refactoring. In my opinion, two big improvements for 5.0.0 could be:
|
Wtf you really did this shit, good job! 👏 |
Just noticed one problem with this patch that I could only detect in a larger test suite. The following will fail: $id = Uuid::uuid4();
self::assertEquals($id, Uuid::fromString($id->toString())); This is because we no longer create a I think I will change the various |
I've added tests that ensure that In applying this change, we managed to get another 10% perf out of that part of the logic 👍
Note: I'm not fond of these hacks, but I think the root cause is still |
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.
Everything here looks great. I see the problem with the factory now. I believe the reason for being able to swap the factory was primarily for testing purposes, but I see now how this design is flawed, so it makes sense to remove that in 5.0.0.
I only have one question about the unwrap()
method.
private function unwrap(): UuidInterface | ||
{ | ||
return (new UuidFactory()) | ||
->fromString($this->uuid); |
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.
Would this make more sense to store to a property so that unwrap()
only calls (new UuidFactory())->fromString()
once per instance?
e.g.,
if ($this->uuidInstance === null) {
$this->uuidInstance = (new UuidFactory())->fromString($this->uuid);
}
return $this->uuidInstance;
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.
It can most certainly be done: possibly worth writing a benchmark for those paths.
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.
I suspect it’d be beneficial when dealing with one Uuid instance and operating on it using multiple methods, but it might be detrimental when using multiple Uuid instances and calling only a single method on each (such as in a loop).
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.
Mostly memory impact, but only when looking at details such as UUID internals
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.
Thinking further about this, the only affected API is getFields
, as everything else is deprecated.
If we add a new private field, we do slow down serialization/deserialization, but that's something I's have to benchmark as well.
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.
Added benchmarks and applied this optimization: it seems like an acceptable trade-off.
Here are the results before/after:
+---------------------------+-------------------------------------------------------------------------+-----+------+-----+------------+-------------+-------------+-------------+-------------+----------+--------+-----------+
| benchmark | subject | set | revs | its | mem_peak | best | mean | mode | worst | stdev | rstdev | diff |
+---------------------------+-------------------------------------------------------------------------+-----+------+-----+------------+-------------+-------------+-------------+-------------+----------+--------+-----------+
| UuidStringConversionBench | benchCreationOfTinyUuidFromString | 0 | 5 | 5 | 6,109,896b | 2.800μs | 2.800μs | 2.800μs | 2.800μs | 0.000μs | 0.00% | 2.33x |
| UuidStringConversionBench | benchCreationOfHugeUuidFromString | 0 | 5 | 5 | 6,109,896b | 2.800μs | 2.800μs | 2.800μs | 2.800μs | 0.000μs | 0.00% | 2.33x |
| UuidStringConversionBench | benchCreationOfUuidFromString | 0 | 5 | 5 | 6,109,888b | 2.800μs | 2.880μs | 2.807μs | 3.000μs | 0.098μs | 3.40% | 2.40x |
| UuidStringConversionBench | benchCreationOfPromiscuousUuidsFromString | 0 | 5 | 5 | 6,109,912b | 155.800μs | 161.200μs | 158.667μs | 169.000μs | 4.735μs | 2.94% | 134.33x |
| UuidStringConversionBench | benchCreationOfTinyUuidFromBytes | 0 | 5 | 5 | 6,109,896b | 5.800μs | 5.840μs | 5.800μs | 6.000μs | 0.080μs | 1.37% | 4.87x |
| UuidStringConversionBench | benchCreationOfHugeUuidFromBytes | 0 | 5 | 5 | 6,109,896b | 5.400μs | 5.480μs | 5.407μs | 5.600μs | 0.098μs | 1.79% | 4.57x |
| UuidStringConversionBench | benchCreationOfUuidFromBytes | 0 | 5 | 5 | 6,109,888b | 5.200μs | 5.400μs | 5.515μs | 5.600μs | 0.179μs | 3.31% | 4.50x |
| UuidStringConversionBench | benchCreationOfPromiscuousUuidsFromBytes | 0 | 5 | 5 | 6,109,912b | 380.800μs | 393.760μs | 392.218μs | 409.400μs | 9.927μs | 2.52% | 328.13x |
| UuidStringConversionBench | benchStringConversionOfTinyUuid | 0 | 5 | 5 | 6,109,888b | 1.200μs | 1.200μs | 1.200μs | 1.200μs | 0.000μs | 0.00% | 1.00x |
| UuidStringConversionBench | benchStringConversionOfHugeUuid | 0 | 5 | 5 | 6,109,888b | 1.200μs | 1.200μs | 1.200μs | 1.200μs | 0.000μs | 0.00% | 1.00x |
| UuidStringConversionBench | benchStringConversionOfUuid | 0 | 5 | 5 | 6,109,888b | 1.200μs | 1.200μs | 1.200μs | 1.200μs | 0.000μs | 0.00% | 1.00x |
| UuidStringConversionBench | benchStringConversionOfPromiscuousUuids | 0 | 5 | 5 | 6,109,896b | 115.200μs | 116.680μs | 115.792μs | 120.000μs | 1.774μs | 1.52% | 97.23x |
| UuidStringConversionBench | benchBytesConversionOfTinyUuid | 0 | 5 | 5 | 6,109,888b | 2.000μs | 2.000μs | 2.000μs | 2.000μs | 0.000μs | 0.00% | 1.67x |
| UuidStringConversionBench | benchBytesConversionOfHugeUuid | 0 | 5 | 5 | 6,109,888b | 2.000μs | 2.000μs | 2.000μs | 2.000μs | 0.000μs | 0.00% | 1.67x |
| UuidStringConversionBench | benchBytesConversionOfUuid | 0 | 5 | 5 | 6,109,888b | 2.000μs | 2.000μs | 2.000μs | 2.000μs | 0.000μs | 0.00% | 1.67x |
| UuidStringConversionBench | benchBytesConversionOfPromiscuousUuids | 0 | 5 | 5 | 6,109,896b | 182.000μs | 189.200μs | 191.148μs | 194.400μs | 4.358μs | 2.30% | 157.67x |
| UuidFieldExtractionBench | benchGetFields | 0 | 5 | 5 | 6,567,712b | 883.200μs | 922.640μs | 922.594μs | 963.400μs | 27.870μs | 3.02% | 768.87x |
| UuidFieldExtractionBench | benchGetFields10Times | 0 | 5 | 5 | 6,567,720b | 1,501.600μs | 1,546.880μs | 1,537.530μs | 1,603.600μs | 33.694μs | 2.18% | 1,289.07x |
| UuidFieldExtractionBench | benchGetHex | 0 | 5 | 5 | 6,578,592b | 910.800μs | 956.920μs | 967.285μs | 985.000μs | 25.444μs | 2.66% | 797.43x |
| UuidFieldExtractionBench | benchGetHex10Times | 0 | 5 | 5 | 6,578,600b | 1,633.400μs | 1,666.440μs | 1,642.168μs | 1,737.600μs | 41.014μs | 2.46% | 1,388.70x |
| UuidFieldExtractionBench | benchGetInteger | 0 | 5 | 5 | 6,912,320b | 1,101.600μs | 1,129.680μs | 1,146.378μs | 1,152.000μs | 22.803μs | 2.02% | 941.40x |
| UuidFieldExtractionBench | benchGetInteger10Times | 0 | 5 | 5 | 6,912,328b | 2,130.800μs | 2,176.040μs | 2,165.507μs | 2,237.000μs | 35.627μs | 1.64% | 1,813.37x |
| UuidGenerationBench | benchUuid1GenerationWithoutParameters | 0 | 5 | 5 | 6,556,760b | 1,144.400μs | 1,188.760μs | 1,184.077μs | 1,223.600μs | 30.154μs | 2.54% | 990.63x |
| UuidGenerationBench | benchUuid1GenerationWithNode | 0 | 5 | 5 | 6,556,536b | 1,181.400μs | 1,202.080μs | 1,204.126μs | 1,219.600μs | 12.196μs | 1.01% | 1,001.73x |
| UuidGenerationBench | benchUuid1GenerationWithNodeAndClockSequence | 0 | 5 | 5 | 6,556,560b | 1,043.200μs | 1,065.720μs | 1,048.704μs | 1,100.600μs | 24.119μs | 2.26% | 888.10x |
| UuidGenerationBench | benchUuid2GenerationWithDomainAndLocalIdentifier | 0 | 5 | 5 | 6,866,968b | 1,387.400μs | 1,403.000μs | 1,394.944μs | 1,436.200μs | 17.327μs | 1.23% | 1,169.17x |
| UuidGenerationBench | benchUuid2GenerationWithDomainAndLocalIdentifierAndNode | 0 | 5 | 5 | 6,866,968b | 1,306.200μs | 1,360.120μs | 1,380.088μs | 1,393.600μs | 33.230μs | 2.44% | 1,133.43x |
| UuidGenerationBench | benchUuid2GenerationWithDomainAndLocalIdentifierAndNodeAndClockSequence | 0 | 5 | 5 | 6,866,984b | 1,320.600μs | 1,372.280μs | 1,387.935μs | 1,412.600μs | 35.368μs | 2.58% | 1,143.57x |
| UuidGenerationBench | benchUuid3Generation | 0 | 5 | 5 | 6,545,208b | 672.200μs | 694.560μs | 689.754μs | 718.200μs | 16.013μs | 2.31% | 578.80x |
| UuidGenerationBench | benchUuid4Generation | 0 | 5 | 5 | 6,545,208b | 659.400μs | 667.360μs | 664.726μs | 676.200μs | 6.056μs | 0.91% | 556.13x |
| UuidGenerationBench | benchUuid5Generation | 0 | 5 | 5 | 6,545,256b | 640.200μs | 652.640μs | 654.649μs | 665.400μs | 9.250μs | 1.42% | 543.87x |
| UuidGenerationBench | benchUuid6GenerationWithoutParameters | 0 | 5 | 5 | 6,556,760b | 1,191.400μs | 1,238.760μs | 1,259.899μs | 1,267.000μs | 30.777μs | 2.48% | 1,032.30x |
| UuidGenerationBench | benchUuid6GenerationWithNode | 0 | 5 | 5 | 6,556,536b | 1,088.800μs | 1,112.600μs | 1,097.812μs | 1,168.200μs | 29.407μs | 2.64% | 927.17x |
| UuidGenerationBench | benchUuid6GenerationWithNodeAndClockSequence | 0 | 5 | 5 | 6,556,560b | 1,099.000μs | 1,112.520μs | 1,104.953μs | 1,138.000μs | 14.597μs | 1.31% | 927.10x |
| UuidSerializationBench | benchSerializationOfTinyUuid | 0 | 5 | 5 | 6,103,264b | 1.600μs | 1.600μs | 1.600μs | 1.600μs | 0.000μs | 0.00% | 1.33x |
| UuidSerializationBench | benchSerializationOfHugeUuid | 0 | 5 | 5 | 6,103,264b | 1.600μs | 1.600μs | 1.600μs | 1.600μs | 0.000μs | 0.00% | 1.33x |
| UuidSerializationBench | benchSerializationOfUuid | 0 | 5 | 5 | 6,103,264b | 1.600μs | 1.600μs | 1.600μs | 1.600μs | 0.000μs | 0.00% | 1.33x |
| UuidSerializationBench | benchSerializationOfPromiscuousUuids | 0 | 5 | 5 | 6,121,448b | 64.000μs | 64.480μs | 64.176μs | 65.000μs | 0.449μs | 0.70% | 53.73x |
| UuidSerializationBench | benchDeSerializationOfTinyUuid | 0 | 5 | 5 | 6,103,264b | 2.200μs | 2.200μs | 2.200μs | 2.200μs | 0.000μs | 0.00% | 1.83x |
| UuidSerializationBench | benchDeSerializationOfHugeUuid | 0 | 5 | 5 | 6,103,264b | 2.200μs | 2.200μs | 2.200μs | 2.200μs | 0.000μs | 0.00% | 1.83x |
| UuidSerializationBench | benchDeSerializationOfUuid | 0 | 5 | 5 | 6,103,264b | 2.200μs | 2.200μs | 2.200μs | 2.200μs | 0.000μs | 0.00% | 1.83x |
| UuidSerializationBench | benchDeSerializationOfPromiscuousUuids | 0 | 5 | 5 | 6,119,456b | 85.200μs | 86.360μs | 86.483μs | 87.400μs | 0.742μs | 0.86% | 71.97x |
+---------------------------+-------------------------------------------------------------------------+-----+------+-----+------------+-------------+-------------+-------------+-------------+----------+--------+-----------+
+---------------------------+-------------------------------------------------------------------------+-----+------+-----+------------+-------------+-------------+-------------+-------------+----------+--------+-----------+
| benchmark | subject | set | revs | its | mem_peak | best | mean | mode | worst | stdev | rstdev | diff |
+---------------------------+-------------------------------------------------------------------------+-----+------+-----+------------+-------------+-------------+-------------+-------------+----------+--------+-----------+
| UuidStringConversionBench | benchCreationOfTinyUuidFromString | 0 | 5 | 5 | 6,153,936b | 2.600μs | 2.720μs | 2.793μs | 2.800μs | 0.098μs | 3.60% | 2.72x |
| UuidStringConversionBench | benchCreationOfHugeUuidFromString | 0 | 5 | 5 | 6,153,936b | 2.400μs | 2.480μs | 2.407μs | 2.600μs | 0.098μs | 3.95% | 2.48x |
| UuidStringConversionBench | benchCreationOfUuidFromString | 0 | 5 | 5 | 6,153,928b | 2.600μs | 2.680μs | 2.607μs | 2.800μs | 0.098μs | 3.66% | 2.68x |
| UuidStringConversionBench | benchCreationOfPromiscuousUuidsFromString | 0 | 5 | 5 | 6,153,952b | 159.400μs | 165.120μs | 167.367μs | 171.200μs | 4.446μs | 2.69% | 165.12x |
| UuidStringConversionBench | benchCreationOfTinyUuidFromBytes | 0 | 5 | 5 | 6,153,936b | 5.200μs | 5.280μs | 5.207μs | 5.400μs | 0.098μs | 1.86% | 5.28x |
| UuidStringConversionBench | benchCreationOfHugeUuidFromBytes | 0 | 5 | 5 | 6,153,936b | 5.200μs | 5.360μs | 5.322μs | 5.600μs | 0.150μs | 2.79% | 5.36x |
| UuidStringConversionBench | benchCreationOfUuidFromBytes | 0 | 5 | 5 | 6,153,928b | 5.200μs | 5.240μs | 5.200μs | 5.400μs | 0.080μs | 1.53% | 5.24x |
| UuidStringConversionBench | benchCreationOfPromiscuousUuidsFromBytes | 0 | 5 | 5 | 6,153,952b | 365.400μs | 381.240μs | 385.598μs | 393.600μs | 11.033μs | 2.89% | 381.24x |
| UuidStringConversionBench | benchStringConversionOfTinyUuid | 0 | 5 | 5 | 6,153,928b | 1.000μs | 1.000μs | 1.000μs | 1.000μs | 0.000μs | 0.00% | 1.00x |
| UuidStringConversionBench | benchStringConversionOfHugeUuid | 0 | 5 | 5 | 6,153,928b | 1.000μs | 1.000μs | 1.000μs | 1.000μs | 0.000μs | 0.00% | 1.00x |
| UuidStringConversionBench | benchStringConversionOfUuid | 0 | 5 | 5 | 6,153,928b | 1.200μs | 1.200μs | 1.200μs | 1.200μs | 0.000μs | 0.00% | 1.20x |
| UuidStringConversionBench | benchStringConversionOfPromiscuousUuids | 0 | 5 | 5 | 6,153,936b | 110.200μs | 115.640μs | 118.770μs | 119.400μs | 4.209μs | 3.64% | 115.64x |
| UuidStringConversionBench | benchBytesConversionOfTinyUuid | 0 | 5 | 5 | 6,153,928b | 2.000μs | 2.000μs | 2.000μs | 2.000μs | 0.000μs | 0.00% | 2.00x |
| UuidStringConversionBench | benchBytesConversionOfHugeUuid | 0 | 5 | 5 | 6,153,928b | 1.800μs | 1.800μs | 1.800μs | 1.800μs | 0.000μs | 0.00% | 1.80x |
| UuidStringConversionBench | benchBytesConversionOfUuid | 0 | 5 | 5 | 6,153,928b | 1.800μs | 1.800μs | 1.800μs | 1.800μs | 0.000μs | 0.00% | 1.80x |
| UuidStringConversionBench | benchBytesConversionOfPromiscuousUuids | 0 | 5 | 5 | 6,153,936b | 166.400μs | 169.360μs | 168.077μs | 174.800μs | 2.899μs | 1.71% | 169.36x |
| UuidFieldExtractionBench | benchGetFields | 0 | 5 | 5 | 6,572,536b | 741.200μs | 769.760μs | 764.918μs | 801.800μs | 20.406μs | 2.65% | 769.76x |
| UuidFieldExtractionBench | benchGetFields10Times | 0 | 5 | 5 | 6,572,544b | 752.200μs | 791.080μs | 802.854μs | 818.400μs | 25.143μs | 3.18% | 791.08x |
| UuidFieldExtractionBench | benchGetHex | 0 | 5 | 5 | 6,583,416b | 791.200μs | 830.160μs | 842.167μs | 859.200μs | 24.198μs | 2.91% | 830.16x |
| UuidFieldExtractionBench | benchGetHex10Times | 0 | 5 | 5 | 6,583,424b | 976.600μs | 1,005.240μs | 992.009μs | 1,038.600μs | 24.271μs | 2.41% | 1,005.24x |
| UuidFieldExtractionBench | benchGetInteger | 0 | 5 | 5 | 6,917,144b | 1,038.200μs | 1,071.960μs | 1,076.645μs | 1,102.400μs | 21.891μs | 2.04% | 1,071.96x |
| UuidFieldExtractionBench | benchGetInteger10Times | 0 | 5 | 5 | 6,917,152b | 1,335.000μs | 1,369.000μs | 1,358.176μs | 1,420.200μs | 31.531μs | 2.30% | 1,369.00x |
| UuidGenerationBench | benchUuid1GenerationWithoutParameters | 0 | 5 | 5 | 6,561,584b | 1,128.400μs | 1,160.200μs | 1,150.947μs | 1,204.200μs | 27.000μs | 2.33% | 1,160.20x |
| UuidGenerationBench | benchUuid1GenerationWithNode | 0 | 5 | 5 | 6,561,360b | 1,058.600μs | 1,092.080μs | 1,080.670μs | 1,134.800μs | 27.082μs | 2.48% | 1,092.08x |
| UuidGenerationBench | benchUuid1GenerationWithNodeAndClockSequence | 0 | 5 | 5 | 6,561,384b | 1,092.000μs | 1,117.040μs | 1,126.834μs | 1,132.000μs | 15.455μs | 1.38% | 1,117.04x |
| UuidGenerationBench | benchUuid2GenerationWithDomainAndLocalIdentifier | 0 | 5 | 5 | 6,871,792b | 1,623.800μs | 1,646.240μs | 1,633.976μs | 1,688.800μs | 23.964μs | 1.46% | 1,646.24x |
| UuidGenerationBench | benchUuid2GenerationWithDomainAndLocalIdentifierAndNode | 0 | 5 | 5 | 6,871,792b | 1,309.400μs | 1,335.040μs | 1,345.401μs | 1,354.600μs | 17.389μs | 1.30% | 1,335.04x |
| UuidGenerationBench | benchUuid2GenerationWithDomainAndLocalIdentifierAndNodeAndClockSequence | 0 | 5 | 5 | 6,871,808b | 1,325.800μs | 1,355.000μs | 1,344.950μs | 1,396.200μs | 24.257μs | 1.79% | 1,355.00x |
| UuidGenerationBench | benchUuid3Generation | 0 | 5 | 5 | 6,550,032b | 670.000μs | 680.040μs | 685.460μs | 689.800μs | 8.350μs | 1.23% | 680.04x |
| UuidGenerationBench | benchUuid4Generation | 0 | 5 | 5 | 6,550,032b | 641.400μs | 670.680μs | 664.213μs | 701.800μs | 21.455μs | 3.20% | 670.68x |
| UuidGenerationBench | benchUuid5Generation | 0 | 5 | 5 | 6,550,080b | 694.200μs | 722.640μs | 719.151μs | 745.200μs | 19.055μs | 2.64% | 722.64x |
| UuidGenerationBench | benchUuid6GenerationWithoutParameters | 0 | 5 | 5 | 6,561,584b | 1,134.200μs | 1,156.240μs | 1,154.181μs | 1,180.400μs | 15.061μs | 1.30% | 1,156.24x |
| UuidGenerationBench | benchUuid6GenerationWithNode | 0 | 5 | 5 | 6,561,360b | 1,078.600μs | 1,115.680μs | 1,100.530μs | 1,161.000μs | 30.601μs | 2.74% | 1,115.68x |
| UuidGenerationBench | benchUuid6GenerationWithNodeAndClockSequence | 0 | 5 | 5 | 6,561,384b | 1,049.800μs | 1,103.640μs | 1,123.668μs | 1,138.200μs | 33.503μs | 3.04% | 1,103.64x |
| UuidSerializationBench | benchSerializationOfTinyUuid | 0 | 5 | 5 | 6,147,304b | 1.600μs | 1.600μs | 1.600μs | 1.600μs | 0.000μs | 0.00% | 1.60x |
| UuidSerializationBench | benchSerializationOfHugeUuid | 0 | 5 | 5 | 6,147,304b | 1.600μs | 1.600μs | 1.600μs | 1.600μs | 0.000μs | 0.00% | 1.60x |
| UuidSerializationBench | benchSerializationOfUuid | 0 | 5 | 5 | 6,147,304b | 1.600μs | 1.600μs | 1.600μs | 1.600μs | 0.000μs | 0.00% | 1.60x |
| UuidSerializationBench | benchSerializationOfPromiscuousUuids | 0 | 5 | 5 | 6,147,312b | 63.800μs | 64.880μs | 64.082μs | 66.800μs | 1.211μs | 1.87% | 64.88x |
| UuidSerializationBench | benchDeSerializationOfTinyUuid | 0 | 5 | 5 | 6,147,304b | 2.200μs | 2.200μs | 2.200μs | 2.200μs | 0.000μs | 0.00% | 2.20x |
| UuidSerializationBench | benchDeSerializationOfHugeUuid | 0 | 5 | 5 | 6,147,304b | 2.200μs | 2.200μs | 2.200μs | 2.200μs | 0.000μs | 0.00% | 2.20x |
| UuidSerializationBench | benchDeSerializationOfUuid | 0 | 5 | 5 | 6,147,304b | 2.200μs | 2.200μs | 2.200μs | 2.200μs | 0.000μs | 0.00% | 2.20x |
| UuidSerializationBench | benchDeSerializationOfPromiscuousUuids | 0 | 5 | 5 | 6,147,312b | 85.800μs | 88.520μs | 89.896μs | 90.400μs | 1.929μs | 2.18% | 88.52x |
+---------------------------+-------------------------------------------------------------------------+-----+------+-----+------------+-------------+-------------+-------------+-------------+----------+--------+-----------+
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.
Thanks!
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.
Note: Uuid::uuid4()
and similar API is still extremely slow.
I don't know if that can be sped up, but it should be another area of focus for 5.x (benchmarks are in place, but I couldn't find an easy-pick source of the problem, not even with XDebug profiling)
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.
Uuid::uuid4() being slow is far less annoying that fromString() and toString() being slow, we create an UUID for an entity or such only once, we load and update it thousands if not millions of time.
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.
@pounard yes, but it is still relevant for anything that generates in-request UUIDs, for example tracing/logging use-cases.
Anyway, the patch here is done as-is :)
…`Uuid#toString()`, `Uuid#getBytes()` This is mostly to store an initial state, before we go on and start manipulating the UUID library internals.
…ing` when possible This should speed up `Uuid::fromString()` massively, leading to much shallower execution paths when `toString()` and similar simplistic API is required.
…ring` where possible
…chmarks This is not indicative of performance, but just guarantees that the benchmarks still run, and that we didn't break them during an upgrade or code change.
…ality guidelines We have a lot of deprecated API in here which shouldn't exist in first place, but that will luckily disappear with v5.0.0 :-)
Co-authored-by: Jacob Dreesen <[email protected]>
…o `Uuid::fromString()` and `Uuid::fromBytes()` With this change, `Uuid::uuid1()`, `Uuid::uuid2()` and so forth now produce a `LazyUuidFromString` instance, which is both more memory efficient and comparable to `Uuid::fromString()` instances in other tools, such as within PHPUnit's `Assertion::assertEqual()`, which would reject any two objects not matching each other's types. Before this patch, `Assertion::assertEquals(Uuid::uuid5(...), Uuid::fromString(...))` would always fail due to different subtypes produced by the two factory methods.
… from purity static analysis checks
…s an internal instance cache for unwrapped instances
441df48
to
0c2b407
Compare
@ramsey could you try tagging this as something like I'd like to see the effects on the wider ecosystem :D |
The generation of Uuid objects received a substantial improvement in this PR ramsey/uuid#324 which introduced the new object being returned from the default UuidFactory.
Just wanted to note that from version 4.0 to version 4.1, this introduction of |
@shehi breakages if you didn't respect the types of the various There is no guarantee that a specific |
Apologies @Ocramius . I took over |
This is mostly to store an initial state, before we go on and start manipulating the UUID library internals.
I'm going to try and iterate over the
Uuid
facade to improve its performance.