Current implementation of string handling in dart is sub optimal:
StringBaseSubstringMatches can be improved to utilize simd instructions. I created simple test utilizing stringzilla library for OneByteStrings and got results showing that performance of indexOf operation can be improved up to 10 times.
dart version 3.5.0-edge.a479f91e80875dd6661b12108c9b81bdaeb2af65
What has been done:
I added another method into String class .String indexOfStrinzilla(String other);
stopwatch.start();
for (int i = 0; i < 100000; i++) {
longStr.indexOfStrinzilla(search);
}
double stringzilla = stopwatch.elapsedMilliseconds / 1;
totalSimd += stringzilla;
stopwatch = Stopwatch();
stopwatch.start();
for (int i = 0; i < 100000; i++) {
longStr.lastIndexOf(search);
}
double dart = stopwatch.elapsedMilliseconds / 1;
totalDart += dart;
print('$j $stringzilla $dart');
}
print('total $totalSimd $totalDart');
}
Results:
total 3695.0 34174.0
Looks like the closer the search string is to the end of the source string the more efficient dart is, however performance of simd only depends on the length of the search string
Also conversion of string encodings can be improved. Dart can have native latin1\utf8\utf16\utf32 encoders decoders based on [simdutf](https://simdutf.github.io/simdutf/) which will significantly improve performance of these operations(See attached benchamrks in the simdutf documentation).
Refactoring [vm/unicode.cc](https://github.com/dart-lang/sdk/blob/main/runtime/vm/unicode.cc) and [platform/unicode.cc](https://github.com/dart-lang/sdk/blob/main/runtime/platform/unicode.cc) makes code up to 3 times more performant in my tests
Current implementation of string handling in dart is sub optimal: StringBaseSubstringMatches can be improved to utilize simd instructions. I created simple test utilizing stringzilla library for OneByteStrings and got results showing that performance of indexOf operation can be improved up to 10 times.
dart version 3.5.0-edge.a479f91e80875dd6661b12108c9b81bdaeb2af65
What has been done:
I added another method into String class .String indexOfStrinzilla(String other);
3.string_path.dart has been modified as well
V(String_indexOfStrinzilla, 2)
In object.cc
void main(List
double totalDart = 0; double totalSimd = 0;
for (int j = 1; j < testStr.length; j++) { String search = "/" * 80; String longStr = testStr.substring(0, j) + search + testStr.substring(j); var stopwatch = Stopwatch();
} print('total $totalSimd $totalDart'); }