Skip to content

win, tty: improve SIGWINCH performance#2381

Closed
bzoz wants to merge 1 commit intolibuv:v1.xfrom
JaneaSystems:bartek-sigwin-perf-update
Closed

win, tty: improve SIGWINCH performance#2381
bzoz wants to merge 1 commit intolibuv:v1.xfrom
JaneaSystems:bartek-sigwin-perf-update

Conversation

@bzoz
Copy link
Copy Markdown
Member

@bzoz bzoz commented Jul 18, 2019

Continuing improvement of SIGWINCH from PR #2308.

Running SetWinEventHook without filtering for the specific PIDs has a significant impact on the performance of the entire system. This PR changes the way SIGWINCH is handled.

The SetWinEventHook callback now signals a separate thread, uv__tty_console_resize_watcher_thread. This thread calls uv__tty_console_signal_resize() which checks if the console was actually resized. The uv__tty_console_resize_watcher_thread makes sure to not to call the uv__tty_console_signal_resize function more than 30 times per second.

The SetWinEventHook will not be installed if the PID of the conhost.exe process that owns the console window cannot be determined. This can happen when a 32bit libuv app is running on a 64bit Windows.

For such cases, PR #1408 is partially reverted - when tty reads WINDOW_BUFFER_SIZE_EVENT, it will also trigger a call to uv__tty_console_signal_resize(). This will also help when the app is running under console emulators. Documentation was also updated to reflect that.

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Jul 18, 2019

CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/1459/
libuv-in-node: https://ci.nodejs.org/view/libuv/job/libuv-in-node/103/

EDIT(cjihrig): In case the CI runs get lost to history - both runs were fine.

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Aug 1, 2019

ping @libuv/collaborators ?

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Aug 8, 2019

ping?

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Aug 29, 2019

ping? @libuv/windows

Copy link
Copy Markdown
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

LGTM with some suggestions and a question. Sorry for the delay, I had this on my TBR (To Be Reviewed) list but it fell through the cracks.

src/win/tty.c Outdated
if (pSetWinEventHook == NULL || pNtQueryInformationProcess == NULL)
if (pSetWinEventHook == NULL || pNtQueryInformationProcess == NULL) {
return 0;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unrelated stylistic change.

LONG idChild,
DWORD dwEventThread,
DWORD dwmsEventTime) {
SetEvent(uv__tty_console_resized);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

uv__tty_console_resized can be NULL here, I think? Is that bad?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It cannot, it wont start the watcher if the event could not be created.

@bnoordhuis
Copy link
Copy Markdown
Member

Can you undo the whitespace changes? The diff is massive now.

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Sep 5, 2019

I know, tried the "batch commit sugestions" thingy, did not work as intended.

Continuing improvement of SIGWINCH from PR libuv#2308.

Running SetWinEventHook without filtering for the specific PIDs has
significant impact on the performance of the entire system. This PR
changes the way SIGWINCH is handled.

The SetWinEventHook callback now signals a separate thread,
uv__tty_console_resize_watcher_thread. This thread calls
uv__tty_console_signal_resize() which checks if the console was actually
resized. The uv__tty_console_resize_watcher_thread makes sure to not to
call the uv__tty_console_signal_resize function more than 30 times per
second.

The SetWinEventHook will not be installed, if the PID of the
conhost.exe process that owns the console window cannot be
determinated. This can happen when a 32bit libuv app is running on a
64bit Windows.

For such cases PR libuv#1408 is partially reverted - when tty reads
WINDOW_BUFFER_SIZE_EVENT, it will also trigger a call to
uv__tty_console_signal_resize(). This will also help when the app is
running under console emulators. Documentation was alos updated to
reflect that.

Refs: microsoft/terminal#1811
Refs: microsoft/terminal#410
Refs: libuv#2308
@bzoz bzoz force-pushed the bartek-sigwin-perf-update branch from 499103f to b2bdecb Compare September 5, 2019 09:20
@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Sep 5, 2019

updated and rebased on master

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Sep 5, 2019

@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Sep 5, 2019

Failures are unrelated.

bzoz added a commit that referenced this pull request Sep 5, 2019
Continuing improvement of SIGWINCH from PR #2308.

Running SetWinEventHook without filtering for the specific PIDs has
significant impact on the performance of the entire system. This PR
changes the way SIGWINCH is handled.

The SetWinEventHook callback now signals a separate thread,
uv__tty_console_resize_watcher_thread. This thread calls
uv__tty_console_signal_resize() which checks if the console was actually
resized. The uv__tty_console_resize_watcher_thread makes sure to not to
call the uv__tty_console_signal_resize function more than 30 times per
second.

The SetWinEventHook will not be installed, if the PID of the
conhost.exe process that owns the console window cannot be
determinated. This can happen when a 32bit libuv app is running on a
64bit Windows.

For such cases PR #1408 is partially reverted - when tty reads
WINDOW_BUFFER_SIZE_EVENT, it will also trigger a call to
uv__tty_console_signal_resize(). This will also help when the app is
running under console emulators. Documentation was also updated to
reflect that.

Refs: microsoft/terminal#1811
Refs: microsoft/terminal#410
Refs: #2308

PR-URL: #2381
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@bzoz
Copy link
Copy Markdown
Member Author

bzoz commented Sep 5, 2019

Landed in 7d950c0

@bzoz bzoz closed this Sep 5, 2019
vtjnash added a commit to vtjnash/libuv that referenced this pull request Aug 2, 2024
The Event should be reset before reading the value, or libuv might miss
an update that occurred too rapidly after the previously one.

Refs: libuv#2381
Refs: libuv#4485
vtjnash added a commit that referenced this pull request Aug 5, 2024
The Event should be reset before reading the value, or libuv might miss
an update that occurred too rapidly after the previously one.

Refs: #2381
Refs: #4485
liujinye-sys pushed a commit to open-vela/apps_system_libuv that referenced this pull request Jul 23, 2025
Continuing improvement of SIGWINCH from PR #2308.

Running SetWinEventHook without filtering for the specific PIDs has
significant impact on the performance of the entire system. This PR
changes the way SIGWINCH is handled.

The SetWinEventHook callback now signals a separate thread,
uv__tty_console_resize_watcher_thread. This thread calls
uv__tty_console_signal_resize() which checks if the console was actually
resized. The uv__tty_console_resize_watcher_thread makes sure to not to
call the uv__tty_console_signal_resize function more than 30 times per
second.

The SetWinEventHook will not be installed, if the PID of the
conhost.exe process that owns the console window cannot be
determinated. This can happen when a 32bit libuv app is running on a
64bit Windows.

For such cases PR #1408 is partially reverted - when tty reads
WINDOW_BUFFER_SIZE_EVENT, it will also trigger a call to
uv__tty_console_signal_resize(). This will also help when the app is
running under console emulators. Documentation was also updated to
reflect that.

Refs: microsoft/terminal#1811
Refs: microsoft/terminal#410
Refs: libuv/libuv#2308

PR-URL: libuv/libuv#2381
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
liujinye-sys pushed a commit to open-vela/apps_system_libuv that referenced this pull request Dec 16, 2025
Continuing improvement of SIGWINCH from PR #2308.

Running SetWinEventHook without filtering for the specific PIDs has
significant impact on the performance of the entire system. This PR
changes the way SIGWINCH is handled.

The SetWinEventHook callback now signals a separate thread,
uv__tty_console_resize_watcher_thread. This thread calls
uv__tty_console_signal_resize() which checks if the console was actually
resized. The uv__tty_console_resize_watcher_thread makes sure to not to
call the uv__tty_console_signal_resize function more than 30 times per
second.

The SetWinEventHook will not be installed, if the PID of the
conhost.exe process that owns the console window cannot be
determinated. This can happen when a 32bit libuv app is running on a
64bit Windows.

For such cases PR #1408 is partially reverted - when tty reads
WINDOW_BUFFER_SIZE_EVENT, it will also trigger a call to
uv__tty_console_signal_resize(). This will also help when the app is
running under console emulators. Documentation was also updated to
reflect that.

Refs: microsoft/terminal#1811
Refs: microsoft/terminal#410
Refs: libuv/libuv#2308

PR-URL: libuv/libuv#2381
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
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