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

Enable FFI+Opcache preload optimization #8

Closed
3 of 5 tasks
lisachenko opened this issue Oct 22, 2019 · 8 comments
Closed
3 of 5 tasks

Enable FFI+Opcache preload optimization #8

lisachenko opened this issue Oct 22, 2019 · 8 comments
Labels
enhancement New feature or request

Comments

@lisachenko
Copy link
Owner

lisachenko commented Oct 22, 2019

Loading/parsing definition of C headers in runtime is not good, also, ffi.enable is equal to preload by default, thus, to make this library active by default, preloading of C headers should be added.

Ideally, this requires some infrastructure support to activate FFI preloading.

@lisachenko lisachenko added the enhancement New feature or request label Oct 22, 2019
@lisachenko
Copy link
Owner Author

Preloading suffers from cyclic dependencies and could not preload classes that depend on each other. Let's say that class A contains a property with type B, which is initialized in constructor. Class B accepts link to the class A (aka parent instance) and stores it in his private typed property. Classes A and B are stored in different files.

In this case preload will fail...

@lisachenko
Copy link
Owner Author

There is a bug in preload + pointer casting that results in memory heap corruption: https://bugs.php.net/bug.php?id=78761

@lisachenko
Copy link
Owner Author

To make preloading work, all FFI calls should be only within the Core class, it will be preloaded by PHP, otherwise calls to FFI are restricted by the ffi.enable option.

@lisachenko
Copy link
Owner Author

Preload mode will only work in following releases of PHP7.4 (RC5 doesn't contain a patch for https://bugs.php.net/bug.php?id=78761)

@lisachenko
Copy link
Owner Author

Opcache preloading is broken, need at least PHP7.4.2 to include a bug fix for https://bugs.php.net/bug.php?id=78918

@lisachenko
Copy link
Owner Author

Windows doesn't support opcache preloading as of 7.4.2. Support was removed by @nikic in php/php-src@59c3dda due to ASLR restrictions for internal classes.

Additional details can be found here: php/php-src#4999

@nikic
Copy link
Collaborator

nikic commented Jan 23, 2020

Note that you can use ffi.preload instead. It works on Windows.

@lisachenko
Copy link
Owner Author

Note that you can use ffi.preload instead. It works on Windows.

Thank you for replying, Nikita! I know about this configuration option, but my header file contains some macros which should be resolved in runtime accordind to platfrom, for example ZEND_FASTCALL, thus ffi.preload can't be used for this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants