Skip to content
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

Use PECL uuid function #937

Merged
merged 6 commits into from
Dec 21, 2019
Merged

Use PECL uuid function #937

merged 6 commits into from
Dec 21, 2019

Conversation

jderusse
Copy link
Contributor

This PR replaces the RamserUUID object uuid_create.

Calls to the PECL library are faster and avoid storing complexe object for nothing.

@stayallive
Copy link
Collaborator

I'm fine with this, the leaner the better.

I am wondering why you have chosen for UUID_TYPE_DCE over UUID_TYPE_RANDOM what we used before (which should be v4). I know those 2 are the same in the polyfill but I can't find any documentation on the PECL extension and if it makes a difference, but I prefer UUID_TYPE_RANDOM better since it's more recognizable for the uninformed reader.

Also the build is failing because you left some @throws comments and unused imports (check the Travis logs) :)

@ste93cry ste93cry changed the base branch from master to develop December 18, 2019 19:34
@ste93cry ste93cry added this to the 2.3 milestone Dec 18, 2019
Copy link
Collaborator

@ste93cry ste93cry left a comment

Choose a reason for hiding this comment

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

Change looks good to me, the only thing I see from the announcement of this polyfill is that:

  • for a v4 UUID the PECL extension is 3.25x slower than the polyfill while Ramsey is 1.30x slower
  • the difference of time between the polyfill and Ramsey is not so big, while it is for the PECL extension (the PECL extension is the slowest while generating v4 UUIDs)

tests/EventTest.php Outdated Show resolved Hide resolved
@stayallive
Copy link
Collaborator

stayallive commented Dec 18, 2019

That is interesting... it seems like ramsey/uuid might not be so bad after all and might be best to keep that since it looks like it is quite a bit faster than the PECL extension.

The polyfill itself is even faster but it looks like with the PECL extension you get a big downgrade in performance (comparing against ramsey/uuid) but without the PECL extension there is a bit of a win.

Overal it might be better to keep ramsey/uuid to be honest.

Good find (by @ste93cry) on the announcement, did not even question the "extension is faster" statement: https://symfony.com/blog/introducing-the-new-symfony-uuid-polyfill

Even more info here: https://jolicode.com/blog/uuid-generation-in-php

@ste93cry
Copy link
Collaborator

Ramsey can use the PECL extension too, however by default its usage is disabled and must be manually enabled, even if it's available. Also I don't know how much this extension is installed, so I cannot comment on it. The downside of this change is that the polyfill automatically uses it if it finds that it's available and there is no way to prevent it

@stayallive
Copy link
Collaborator

I agree, so if the consideration to make this change is speed I think this is going backwards when the PECL extension is actually installed and only slightly better if it's not :)

As far as I've gathered the PECL extension might be more secure/resistent to collisions since it uses a better random source, but that is not critically important in this case.

@ste93cry
Copy link
Collaborator

Ramsey should use the random_bytes feature of PHP as far as I saw, but I didn't look at the full source code. One of the reasons I chose it instead of keeping the custom function like in 1.x was because it's a battle-tested library with a strong and safe implementation. I really think that the only thing that should be taken in consideration here is if we want to depend on such 3rd party library just to generate a string (because we only do that) or if we are keen to slow down things for users having the PECL extension installed but make it faster, but probably less safe, for those who don't. One of the reasons the extension is slower is because it opens a file descriptor to /dev/urandom every time a UUID v4 is generated

https://jolicode.com/blog/uuid-generation-in-php

Given that this change is just an internal change and doesn't affect in any way the public API it makes sense in my opinion to merge it and accept the tradeoffs of slowing things down if the extension is enabled because I doubt that such extension is so commonly used

@jderusse
Copy link
Contributor Author

Thank for your review and comments. Yes PECL, is 3 micro seconds slower than Ramsey/polyfill.
But I think that Event are not instanciated that often, and we can afford it.

The purpose of this PR was more about removing a dependency to a package (that already have 3 major version and a 4th in dev) and removing the burdon of maintaing/updating the dependency while keep Backward Compatibility with old version.

Feel free to close the PR if you think we won't affort such performance drawback, I wouldn't be offended 😉

Copy link
Collaborator

@stayallive stayallive left a comment

Choose a reason for hiding this comment

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

Given that this change is just an internal change and doesn't affect in any way the public API it makes sense in my opinion to merge it and accept the tradeoffs of slowing things down if the extension is enabled because I doubt that such extension is so commonly used

This is a good point @ste93cry, in that case i'm also down for this!


Edit: I've upped the dependent version of the polyfill because symfony/polyfill#209

@ste93cry
Copy link
Collaborator

The purpose of this PR was more about removing a dependency to a package

As I already said, I'm more than happy to drop a dependency if we can and it makes sense and in this case for what we are doing which is just generating a UUID and then converting it to a string it totally makes sense, so you have my approval for the change. There is just that small change on the test class that I requested, then for me LGTM

@stayallive
Copy link
Collaborator

stayallive commented Dec 18, 2019

I've made the change on the test class (for the @throws) and just upped the version constraint for the polyfill (see: symfony/polyfill#209). Should be all good now :)

@jderusse
Copy link
Contributor Author

tests are green. (sorry @stayallive i force-pushed you commit).

Looks like Appveyor is out

@ste93cry
Copy link
Collaborator

Looks like Appveyor is out

I'm looking at the issue, since PHP 7.1 is not maintained anymore the link to download the Windows version is not working anymore 🤦‍♂

@stayallive
Copy link
Collaborator

@jderusse looks like everything is here so no worries :)

Just some AppVeyor issues, but the PR is solid, thanks!

Copy link
Collaborator

@Jean85 Jean85 left a comment

Choose a reason for hiding this comment

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

Very good job everyone, this PR is pretty solid! Let's hope to fix AppVeyor ASAP... Maybe we can look at how Symfony fixed its build?

@ste93cry
Copy link
Collaborator

@jderusse can you please force push to retrigger the CI? Once all checks are green I will merge

@jderusse
Copy link
Contributor Author

@ste93cry Done. But this PR targets develop (changed by you 2 days ago) While #938 has been merged in master.

@ste93cry
Copy link
Collaborator

Yes sorry my bad, I didn't notice it! I will rebase master on develop as soon as possible and then we should be fine here too

Copy link
Collaborator

@ste93cry ste93cry left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for the hard work

@ste93cry ste93cry merged commit bfb2a40 into getsentry:develop Dec 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants