Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-2288

Refactor logger and subscriber method invocation to use zend_call_function()

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Performance
    • None

      The initial implementation of logging in PHPC-2180 uses call_user_function to invoke a logging callback. This is similar to zend_call_method, which is used in phongo_apm.c to dispatch subscriber callbacks, in that it creates zend_fcall_info (FCI) and zend_fcall_info_cache (FCC) structs for each invocation.

      The Callables chapter of the PHP internals book talks about using zend_call_function, which takes FCI and FCC structs, as a more optimal way to invoke functions repeatedly.

      Before making the effort to change the logging and APM components in PHPC, we should determine if the logging/APM use case is even a candidate for pre-computing FCI and FCC structs. While each PHP method can be calculated at the time a logger or subscriber is registered, the parameter(s) vary with each invocation. If that requires modifying FCI/FCC structs with each invocation, there may be little benefit at all in refactoring PHPC to initialize them in advance.

      And lastly, if we do move forward, we should devise some benchmarks to calculate the overhead of repeatedly creating FCI and FCC structs. There may be only a modest performance improvement in doing so, which may not be worth the increased complexity and exposure to PHP's internal APIs. The FCI and FCC structs are subject to change between minor PHP versions, while the current APIs we use are considerably more stable by comparison.

      should try to collect some benchmark info on the actual overhead involved with repeatedly creating FCI and FCC structs. Also, while the methods themselves can be calculated at the time a logger or event subscriber is registered, the arguments vary with each invocation.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: