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
String.substring - very low performance #27810
Comments
V8, used by node.js, has a cheap substring operation for short-lived substrings. It creates a small object that points into the original string. I believe the substring "slice" is converted to a real string when it's garbage collected, so keeping a lot of substrings alive for a long time will eventually cost anyway, but if it's thrown away immediately, then it's cheap. The cost of this optimization is that V8 needs handle one more type of string in all places where it handles strings. This complicates both the runtime system and garbage collection. The Dart VM doesn't have an optimization like this. If you make a 99900 character substring of another string, you copy 99900 characters. |
@lrhn, I understand it. People porting libraries from nodejs negative talk about performance dart vm. We need a class that supports this behavior or some kind of solution to the problem. |
We need to see something more complete than microbenchmark - then we can give some solution. Which library are people trying to port and where is the bottleneck? @lrhn I don't think slice is ever flattened - so you just have essentially a memory leak. |
@Aetet Is there some canonical benchmark I can run against your code to see huge impact on performance? e.g. if you give us some less file that compiles 10x slower then we can nail it down. |
@mraleph. Output:
big1.less
|
I looked into this. It seems that To be honest I think that the best way to fix those overheads is to rewrite the A: Implement string slices in the VM I don't think this is likely to happen. It's quite a bit of complexity that helps only few cases, while introducing subtle memory leaks. Developers should write their code under expectation that B: Add APIs that would make calling substring unnecessary For example ES2015 adds sticky flag that allows you to create regexps that stick to a particular index in the string - i.e. they match if and only if there is a match starting at that index. In reality we already have similar API on the I made some prototype changes to the VM and So to summarize my suggestions: @Aetet if you don't want to rewrite the @DisDis: are you also using /cc @ErikCorryGoogle |
|
@DisDis I started pushing out optimization commits into my fork of your fork of
I think this issue can be closed. Though I do have few other cleanups to push out into |
@mraleph. It is very cool. |
@mraleph 'RegExp.matchAsPrefix' will be in Dart 1.21? |
@DisDis Running |
I created a mini performance test for String.substring
https://github.com/DisDis/dart_vs_nodejs_substring
Dart VM version: 1.20.1 (Wed Oct 12 22:00:54 2016) on "linux_x64"
NodeJs slice string test
Dart slice (substring) string test
dart ~450 times slower nodejs.
Observatory says
The text was updated successfully, but these errors were encountered: