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

Don't use SEND_ONCE mach rights for async, use a queue limit of 1 #102

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

mitchellh
Copy link
Owner

@mitchellh mitchellh commented Jun 24, 2024

SEND_ONCE allocates a mach port with a SEND right exactly once and deallocates it automatically once the message is read. This is totally wasteful because we have a perfectly good mach port already... This commit adds the send right to our existing mach port and reuses it for each send. This avoids any port allocations.

We additionally call mach_port_set_attributes to set the queue limit for the mach port to 1. We don't need to allocate and queue a bunch of messages when all we need is 1 to wake up. This should speed up notifications AND waiting because draining will only ever drain 1.

Related bug for those with access: https://github.com/ghostty-org/ghostty/issues/1836

SEND_ONCE allocates a mach port with a SEND right exactly once and
deallocates it automatically once the message is read. This is totally
wasteful because we have a perfectly good mach port already... This commit adds
the send right to our existing mach port and reuses it for each send. This
avoids any port allocations.

We additionally call mach_port_set_attributes to set the queue limit for
the mach port to 1. We don't need to allocate and queue a bunch of
messages when all we need is 1 to wake up. This should speed up
notifications AND waiting because draining will only ever drain 1.
@mitchellh mitchellh merged commit a42b74a into main Jun 24, 2024
4 checks passed
@mitchellh mitchellh deleted the machport branch June 24, 2024 04:29
mitchellh added a commit that referenced this pull request Jun 24, 2024
SEND_ONCE allocates a mach port with a SEND right exactly once and
deallocates it automatically once the message is read. This is totally
wasteful because we have a perfectly good mach port already... This
commit adds the send right to our existing mach port and reuses it for
each send. This avoids any port allocations.

We additionally call mach_port_set_attributes to set the queue limit for
the mach port to 1. We don't need to allocate and queue a bunch of
messages when all we need is 1 to wake up. This should speed up
notifications AND waiting because draining will only ever drain 1.

Related bug for those with access:
ghostty-org/ghostty#1836
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.

1 participant