nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.15k stars 29.37k forks source link

Pasting very long strings freezes node REPL on MacOS #43343

Open JoBrad opened 2 years ago

JoBrad commented 2 years ago

Version

18.3.0

Platform

Darwin SoMuchBiggerOnTheInside-2.local 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

How often does it reproduce? Is there a required condition?

I can replicate these symptoms every time. Note that I can paste the entire jQuery library into a Python REPL (in the same iTerm2 tab) without any freezing at all. The fact that the for keyword changes behavior makes me think the error is happening when parsing the language. It may be a regression of #32999 (or a similar bug, for Macs), but pasting the 1000 "a" commands in the gist below (mentioned in #32999 comments) does not cause the REPL to freeze.

https://gist.githubusercontent.com/bzoz/bba634114402fee35554f4972a0887b6/raw/c71217ab21ecdf8d6e0874e955fe3b780df4e89f/aaaaaa.txt

What is the expected behavior?

I expect the REPL to accept the pasted text.

What do you see instead?

The REPL freezes or only shows part of the pasted text.

Additional information

No response

mscdex commented 2 years ago

Possibly a duplicate of https://github.com/nodejs/node/issues/40626

JoBrad commented 2 years ago

Not a duplicate. My REPL isn’t reacting slowly, it’s completely freezing and is unresponsive. For instance, when passing the first 128 lines of the jQuery library, the paste operation is pretty quick.

mscdex commented 2 years ago

Both issues are about performance issues with pasting very long lines into the REPL. The REPL implementation currently has to continuously re-scan the entire line buffer after every chunk it receives, which is why it's not a problem with short lines.