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

perf - removes pinning #1295

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

perf - removes pinning #1295

wants to merge 3 commits into from

Conversation

AlliBalliBaba
Copy link
Collaborator

I noticed that it's not necessary to pin a string if it's being used explicitly during a CGO function call (see also this discussion in the google forums.

zend_string_init will always copy the underlying string anyways so removing pinning for most globals is safe.

In the flamegraphs you can see that Pinner.Pin and Pinner.Unpin currently consume around 7% of the CPU profile for the optimized 'Hello World'. Without Pinning most of that time is gone.

With Pinner
flame

Without Pinner
flame

The only way to optimize this even more would be by directly using the allocated go string as a zend_string (not sure if this is currently possible)

Copy link
Owner

@dunglas dunglas left a comment

Choose a reason for hiding this comment

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

Good idea

@withinboredom
Copy link
Collaborator

NICE!

The only way to optimize this even more would be by directly using the allocated go string as a zend_string (not sure if this is currently possible)

That would require pinning. From the thread you linked to:

Unless, the C function stores the pointer and it's kept after the call returns, correct? That's what I mean by calling the function keep_this_pointer in the second example. In this case, it would be necessary, I'm assuming?

Ah, yes, in that case the pointer does have to be pinned.

@AlliBalliBaba
Copy link
Collaborator Author

That would require pinning. From the thread you linked to:

I guess you're right. So maybe this is the most efficient way to pass a string to PHP currently. I know that CGO calls themselves have some overhead because of entersyscall and exitsyscall. But that overhead seems to be smaller than that from pinning.

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

Successfully merging this pull request may close these issues.

4 participants