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

Read multiple bytes for system events #10

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

Conversation

tlsomers
Copy link

When checking for system events, the current version would read 1 byte per iteration, meaning that when other tasks are ready, reading n bytes becomes interleaved with n other tasks. These tasks may be slow, resulting in unnecessary slowdowns of system events (such as UI events in vscoq).

This change allows reading another byte from its file descriptor when:

  1. The system event has lower priority than the lowest priority ready event
  2. The event just read an available byte from the file descriptor.

@gares
Copy link
Owner

gares commented Nov 18, 2023

Thanks for your contribution, I'll try to double check the code again on Monday, but it looks OK to me.
One thing I'd like to have is a test. I think you can verify the invariant by using 2 pipes and two events of different priorities.
You can then check the second pipe is still full after sel returns with the first event being ready.
Some benchmarking would also be nice, but I don't have a proper infrastructure.

There is another approach that may be worth considering:

  • read more data here
    let n = Unix.read fd buff 0 1 in
  • pass the extra data (after the \n) to the following event:

    sel/lib/events.ml

    Lines 166 to 170 in bccdff5

    one_line ()
    --? (parse_content_length_or (finish_with k) (fun length ->
    one_line ()
    --? (fun _discard ->
    some_bytes length ()

I suspect that VSCode sends the whole header in one go (and maybe also the payload). In this way the number of iterations of the loop pulling ready events is going to decrease substantially.

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.

2 participants