-
Notifications
You must be signed in to change notification settings - Fork 19
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
I ported this library in dart #25
Comments
Hi @edwardez can you provide some benchmarks? Is this faster than JS version? :) And of course, I add a link to this lib to Readme in footer :) |
I did some tests but the result is somewhat confusing. Test procedureTested on a 2.6GHz i7 mac laptop. 1. Test js
~ 9 ms? 2. Test dartCode is under Result: Dart JIT
Dart AOT(compile to native code)
Here's the interesting part.
Tl:dr: Original JS: 9ms, dart ~ 19ms, compile dart to js : 5ms It's kind of counter-intuitive as the fatest version is dart2js. I opened a aws t2.micro with AMI2, and tried again.
Not sure if I'm missing something here... |
Wow, interesting results. Maybe Dart needs other approaches. Anyway thanks! |
@edwardez this is the same issue that was described here for less.dart. tl;dr version is that JavaScript engines usually optimize substring by introducing sliced string representation, while Dart VM does not. The problem is quite obvious in the Observatory, because you can see most of the time (60%) is spent creating substring in Try remeasuring with this simple patch: diff --git a/lib/src/bbob_parser/utils.dart b/lib/src/bbob_parser/utils.dart
index 430659e..8e1d038 100644
--- a/lib/src/bbob_parser/utils.dart
+++ b/lib/src/bbob_parser/utils.dart
@@ -22,9 +22,6 @@ class CharGrabber {
/// Whether [CharGrabber] is at the end of [_source].
bool get isLast => _index == _source.length - 1;
- /// Returns rest of the [_source] starting from current position.
- String get rest => _source.substring(_index);
-
/// Gets character that's at the current scan [_index].
String get current => _index >= _source.length ? null : _source[_index];
@@ -49,11 +46,10 @@ class CharGrabber {
/// Grabs rest of string until [CharGrabber] finds [char].
String substringUntil(String char) {
- final rest = this.rest;
- final indexOfChar = rest.indexOf(char);
+ final indexOfChar = _source.indexOf(char, _index);
if (indexOfChar >= 0) {
- return rest.substring(0, indexOfChar);
+ return _source.substring(_index, indexOfChar);
}
return ''; I am getting 7ms with this patch and 22ms without. This also explains dart2js vs VM difference - because dart2js benefits from JS engine implementation of the substrings. (In general if you find any sort of puzzling Dart performance issues - just don't hesitate to contact me directly, we'll take a look). |
Thanks for looking into it! I tried to profile using observatory but it showed up a blank page on firefox, I thought some special setup is needed then got stuck(just realized I cannot use firefox dart-lang/sdk#34107 ). I just tried to open observatory in chrome and can confirm the same behavior. After reducing usage of frequently creating substring, amazing! I'm getting 8ms for parsing all tags and 6ms for parsing with |
Hi @JiLiZART,
Just FYI, I happened to need a bbcode parser in dart but there are no available libraries so I decided to port bbob at https://github.com/edwardez/bbob_dart , now parser has been ported.
Thanks for creating this awesome library!
Regards,
Edward
The text was updated successfully, but these errors were encountered: