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

Remove bcmath dependency #694

Closed
terrafrost opened this issue May 26, 2019 · 5 comments
Closed

Remove bcmath dependency #694

terrafrost opened this issue May 26, 2019 · 5 comments
Assignees
Milestone

Comments

@terrafrost
Copy link

terrafrost commented May 26, 2019

See https://github.com/phpseclib/bcmath_compat .

It basically turns phpseclib's BigInteger class into a BigDecimal class.

Surprisingly, the shim is actually faster than the original bcmath extension for certain operations. Using https://pastebin.com/x8wJBK4F (which, admittedly, is running off of phpseclib/phpseclib:dev-master - not off of the 2.0 branch) I get the following results:

  • bcmath extension took 0.70488119125366 seconds
  • phpseclib with PHP32 engine took 0.52849411964417 seconds
  • phpseclib with BCMath engine took 0.48794078826904 seconds
  • phpseclib with PHP64 engine took 0.23811507225037 seconds
  • phpseclib with GMP engine took 0.0025088787078857 seconds

The fact that phpseclib is able to do modular exponentiation with bcmath faster than bcmath, itself, can is due to the fact that phpseclib (dev-master) uses barrett modular reduction whereas bcmath doesn't. And those results are without OpenSSL, which is used, as well, if it's available, for even faster modular exponentiation.

@lukebakken lukebakken added this to the 2.10.0 milestone May 26, 2019
@lukebakken lukebakken self-assigned this May 26, 2019
@lukebakken
Copy link
Collaborator

Please see #573. If that is a reasonable option, please fix the issues I found with that pull request, or open a new one to address your request here.

Remember that this library is maintained by volunteers, so contributing code (with tests) is the best way to help.

@terrafrost
Copy link
Author

terrafrost commented May 27, 2019

@lukebakken - see #695.

I'm not sure that #573 is really all that applicable. It looks like that is attempting to replace bcmath with floats. This just updates php-amqplib to use a bcmath polyfill.

Other famous polyfill's are ircmaxell/password-compat, paragonie/random_compat, paragonie/sodium_compat, ramsey/array_column, etc. Symfony has a whole collection of polyfill's, as well, for such things as mbstring, etc. They're supposed to be just drop in replacements for missing extensions or out-of-date PHP versions.

One thing that would be cool is Travis CI could run two versions of each PHP VM - one with bcmath and one without. But alas I do not know how to set it up to do that. I posted about this at https://stackoverflow.com/q/56318348/569976 in an attempt to figure out how this might be done.

@ramunasd
Copy link
Member

@terrafrost Regarding travis, You can disable extension before tests and then run tests 2 times, with and without extension.

@lukebakken lukebakken modified the milestones: 2.10.0, 3.x.x Aug 8, 2019
@lukebakken
Copy link
Collaborator

Moved to 3.x.x as we are waiting on an update to #695

@lukebakken
Copy link
Collaborator

Fixed by #754

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

No branches or pull requests

3 participants