Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

process.stdout.on('resize') delayed ~100ms #9032

Closed
arjunmehta opened this issue Jan 14, 2015 · 9 comments
Closed

process.stdout.on('resize') delayed ~100ms #9032

arjunmehta opened this issue Jan 14, 2015 · 9 comments
Labels

Comments

@arjunmehta
Copy link

I'm on OS X 10.10, using the terminal app, though I'm not sure if that has to do with anything.
Tried with node 0.10.35, and latest 0.11.14

It seems the event called when the terminal is resized is delayed by about ~100ms. To demonstrate: I'm simply logging the current column width when the terminal resizes, using the code below:

process.stdout.on('resize', function() {
    console.log(process.stdout.columns);
});

setInterval(function(){}, 1000); // just to keep the script running

It seems when I resize the window really fast, the event is fired quickly and as expected, but then there is a final delay of about 100ms and it fires the last event with an accurate number of columns.

If I drag the window slowly there is also a 100ms delay.

Is this a system level thing? Is there any way to update the columns faster than they are currently being reported? A good example of a responsive application would be top, you can see that it responds to the terminal width instantaneously.

Please let me know if I can help more in any way!
Thanks

@amir-s
Copy link

amir-s commented Jan 16, 2015

I tested the code on my machine and I had the same issue. I also used a mac to do so.

When I resized the window fast numbers are printing out as expected, but when I resize fast and stop, the final number prints after a short delay.

I just took a quick look at https://github.com/joyent/node/blob/master/src/node.js#L505 and it seems the event SIGWINCH is firing with a delay. It might be because of a lower level thing. Or maybe the event loop is busy or something!

@idx3d
Copy link

idx3d commented Jan 19, 2015

I have tested it as well. I have no delay on OS X Yosemite 10.10.1.

^^ Sorry I was mistaken. I was using iojs, not node.

@trevnorris
Copy link

Could any of you test this PR: #9179 and let me know if it fixes the problem?

@amir-s
Copy link

amir-s commented Feb 12, 2015

@trevnorris I checked out and that doesn't solved the problem. There is still delays for the final result.

I also tested the problem against iojs-v1.0.4 and it seems the problem exists there too.

@trevnorris
Copy link

@bnoordhuis Calling you in, since this also affects io.js. Any ideas why this could be happening?

@bnoordhuis
Copy link
Member

It sounds like it could be either a Terminal.app quirk or a delay between libuv receiving the signal and the signal bubbling up to JS land.

Libuv uses the self-pipe trick: the signal handler writes a message to a pipe, which wakes up the thread that makes the call into JS land.

I would start by timing the gap between receipt of the signal and the event loop waking up. I don't know if there's a dtrace/dtruss trick for that but on Linux, you would use strace -f -tt (the -f flag because the signal can come in on any thread, -tt for microsecond timestamps.)

@arjunmehta
Copy link
Author

I just tested this with your PR #9179 as well as io.js v1.2.0 and still find this issue exists.
Also, I tested with iTerm2 and seems to be happening with it as well, but I wonder if perhaps iTerm and Terminal.app might share some libraries (totally clueless about that kind of thing).

Is anyone able to test this on Windows or Linux to see if it exists there too? Or is this only Mac specific?

@amir-s
Copy link

amir-s commented Feb 13, 2015

The weird thing is if we resize the terminal fast, bunch of SIGWINCH events will be fired except for the last event. I mean assume every resize will fire its SIGWINCH event after a short delay OR when another resize happen.

@arjunmehta
Copy link
Author

I just tested this on Ubuntu Desktop 14.04, and it doesn't present this issue at all.

@Trott Trott closed this as completed Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants