-
Notifications
You must be signed in to change notification settings - Fork 37.2k
Faster __vsc_escape_value for bash #190899
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
Conversation
84a3540 to
d0b8386
Compare
| # We default to use the second function, but if env VSCODE_SHELL_FULL_ESCAPE is set and od, tr are | ||
| # available, we will switch to the first one. | ||
| if [ -n "$VSCODE_SHELL_FULL_ESCAPE" ] && command -v od &>/dev/null && command -v tr &>/dev/null; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is VSCODE_SHELL_FULL_ESCAPE required because you're concerned about breakages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both solutions have their pros and cons, so I temporarily make one of them as default and the other opt-in controlled by a newly introduced flag VSCODE_SHELL_FULL_ESCAPE, but this is apparently not the most optimal solution. I am open to consider any further advice as you see fit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we perhaps select a magic number for $1 length and opt for the new approach when it's above that threshold?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable. What about make it 2000 bytes? This is a point where I can observe around 0.1s delay with the old method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On your machine how long does the new method take? 100ms is quite large still
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some benchmarks
| Input size (bytes) | string sub(new default) | od+tr(new opt-in) | old |
|---|---|---|---|
| 2k | 1ms | 5ms | 107ms |
| 100k | 33ms | 48ms | >1 min |
I think with the new method the overhead is tolerable even with quite large input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They both seem very fast. If I understand right, the od+tr method is superior as it escapes more correctly. Since perf is comparable, I think we should default to the od+tr method if they're available without an opt-in variable, then fallback to the more naive method when they're not available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I will change accordingly. Shall we still set up the magic number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let's make it 2k
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, is /dev/null always available for the execution context of shellIntegration-bash.sh? The script is using command -v od &>/dev/null to detect the availability of od.
Edit: never mind. I found solution to get around it.
961cfa0 to
f8e932f
Compare
|
The latest push contains these further modification:
|
bba6901 to
d273696
Compare
d273696 to
440896c
Compare
Tyriar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hsfzxjy, this looks good. I'll wait until next month to merge so we get some testing in Insiders before it goes out.
5c76f39 to
2067753
Compare
|
Accidental force push dimissed the reviews. Sorry! 🙏 |
|
This ended up getting reverted due to a hang #190255 (comment) |
Fix #190255
This PR presents two faster escaping functions as the replacement of the original slower one.
The first one escapes each byte 0xab into '\xab', which is most scalable and has promising runtime
efficiency, except that it relies on external commands
odandtr.The second one utilizes bash builtin string substitution, which is much faster and has zero dependency, except that it escapes only
'\\' -> '\\\\'and';' -> '\x3b', which scales up badly for more patterns.Currently it defaults to use the second function, but if env
VSCODE_SHELL_FULL_ESCAPEis set andod,trareavailable, it will switch to the first one.
We may discuss more on the choice of the implementation.