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

fix: Allow hooks to be removed after class binding #2422

Closed
wants to merge 2 commits into from

Conversation

PROFeNoM
Copy link
Contributor

@PROFeNoM PROFeNoM commented Dec 13, 2023

Description

During the micro benchmarking process, I came across an unexpected behavior related to #2367. The goal of the latter was most notably to introduce minimal overhead when injecting logs while instrumenting Psr\Log\NullLogger. However, the results showed otherwise (refer to the Before/After comparison below).

The problem arises when the call to \DDTrace\remove_hook is made after a class bind (zen_compile.c:do_bind_class). As a result, the observers-related code (zend_observer.c: _zend_observer_class_linked_notify) does not get executed. This implies that hook.c:zai_hook_resolve_class and hook.c:zai_hook_is_excluded are not called either. Thus, when the supposedly removed class is called again, there is no check to see if the hook was removed or not and we directly go to zend_observer.c:_zend_observe_fcall_begin & hook.c:zai_hook_continue. This pull request addresses this issue by adding the necessary check.

From a general perspective, it was only effective to remove a hook before a class binding occurs. Attempting to remove a hook at any other point was ineffective.

While microbenchmarks are still being developed, the before/after comparison below shows the effect of logs injection (Injection) versus no logs injection (Baseline):
Before:
image

After:
image

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

@PROFeNoM PROFeNoM added 🐛 bug Something isn't working c-extension Apply this label to issues and prs related to the C-extension labels Dec 13, 2023
@PROFeNoM PROFeNoM self-assigned this Dec 13, 2023
@PROFeNoM PROFeNoM requested a review from a team as a code owner December 13, 2023 12:36
Copy link
Member

@realFlowControl realFlowControl left a comment

Choose a reason for hiding this comment

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

The tests are looking good and are ✅
@morrisonlevi knows more about the tracer, so if it is okay, let's wait for his review

Copy link
Collaborator

@morrisonlevi morrisonlevi left a comment

Choose a reason for hiding this comment

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

I'm not sure about the intricacies about removing hooks and such. I've reviewed code around this before but it's been a while and nothing is fresh. It would take quite some time for me to get back into it. It looks fine to me, but if you want to be extra careful and have me take the extra time to review the deeper impact, let me know.

@bwoebi
Copy link
Collaborator

bwoebi commented Jan 4, 2024

Superseded by #2449.

@bwoebi bwoebi closed this Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working c-extension Apply this label to issues and prs related to the C-extension
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants