Rocket is a parsing framework for parsing using efficient parsing algorithms

41 views
Skip to first unread message

Andrew Mezoni

unread,
May 29, 2021, 11:42:14 AM5/29/21
to Dart Misc

The Rocket is a professional developers framework.  
The Rocket is a framework for the rapid development of fast parsers.  
Implement something properly once and reuse it everywhere.  
Parse data as efficiently as possible.  
Use the capabilities of the framework in combination with your own parsers.  
Combine handwritten algorithms with built-in parsers for maximum efficiency.  

Below are the results of testing JSON parsers. Dart SDK JSON parser and JSON parser implemented using Rocket.  

JIT:

```
Dart SDK JSON: k: 1.00, 42.85 MB/s, 501.03 ms (50.71%),
Rocket JSON  : k: 1.97, 21.73 MB/s, 988.06 ms (100.00%),

Parse 10 times: E:\prj\test_dart_json_parsers\bin\data\citm_catalog.json
Dart SDK JSON: k: 1.00, 86.23 MB/s, 191.01 ms (58.23%),
Rocket JSON  : k: 1.72, 50.21 MB/s, 328.02 ms (100.00%),

Parse 10 times: E:\prj\test_dart_json_parsers\bin\data\twitter.json
Dart SDK JSON: k: 1.00, 53.62 MB/s, 101.01 ms (74.27%),
Rocket JSON  : k: 1.35, 39.82 MB/s, 136.01 ms (100.00%),
```

AOT:

```
Parse 10 times: E:\prj\test_dart_json_parsers\bin\data\canada.json
Dart SDK JSON: k: 1.00, 12.28 MB/s, 1748.10 ms (41.98%),
Rocket JSON  : k: 2.38, 5.16 MB/s, 4164.24 ms (100.00%),

Parse 10 times: E:\prj\test_dart_json_parsers\bin\data\citm_catalog.json
Dart SDK JSON: k: 1.16, 23.90 MB/s, 689.04 ms (100.00%),
Rocket JSON  : k: 1.00, 27.73 MB/s, 594.03 ms (86.21%),

Parse 10 times: E:\prj\test_dart_json_parsers\bin\data\twitter.json
Dart SDK JSON: k: 1.00, 45.90 MB/s, 118.01 ms (67.82%),
Rocket JSON  : k: 1.47, 31.13 MB/s, 174.01 ms (100.00%),
```

The Rocket JSON parser was written in a few hours.  
The parser can be complicated to improve performance by adding some kinds of tweaks (as it was done in the Dart SDK parser), but this will impair the clarity of the parsing algorithms and, in principle, reduce its reliability (theoretically).  

Randal L. Schwartz

unread,
May 29, 2021, 1:39:52 PM5/29/21
to Andrew Mezoni, Dart Misc
>>>>> "Andrew" == Andrew Mezoni <andrew...@gmail.com> writes:

Andrew> https://github.com/mezoni/rocket
Andrew> https://pub.dev/packages/rocket

I really really want to learn this and use it, but until you get more
documentation, it would be an exercise in reverse engineering.

I would kindly ask that you not taunt us with potential goodies like
this until it would be possible to understand how to use it.

Please remember that for any product, the docs *are* the product in the
consumer's eyes.

Thank you.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Dart/Flutter consulting, Technical writing, Comedy, etc. etc.
Still trying to think of something clever for the fourth line of this .sig

Andrew Mezoni

unread,
May 29, 2021, 2:37:16 PM5/29/21
to Dart Misc, Randal L. Schwartz, Dart Misc, Andrew Mezoni
Thank you, Randal.
I know. But for me, writing the documentation is overwhelming work). Oh...
I am a businessman. I am not a programmer. I need to buy goods for the store (including in China), and also sell them.
Do you know how much time I spent on research in this direction (theoretical and practical parts, including coding, testing and rethinking and reimplementing.)?
Much more than it takes to write this simple code.
I rewrote the code 5 or 6 times.
It was exhausting but exciting.
It all works now and looks good. But initially it did not behave that way. Of course, everything worked as it should then, but not as efficiently.
Oh, this is titanic work.
I'm glad that everything is over and everything is working almost the way I wanted.
But it is still a crude product.
Dart is not the most suitable language for this kind of thing. In the sense of brevity and expressiveness.
And Dart is unpredictable in terms of performance.

I need time for rest and business.

>>  it would be an exercise in reverse engineering.

Try it on simple things as such.

import 'package:charcode/ascii.dart';
import 'package:rocket/parse.dart';

void main() {
  final p1 = not(char($space)).right(anyChar());
  final p2 = char($space).skipMany.right(sepBy(p1.many1, char($space).many1));
  final r = p2.parseString('  123   456 7 ');
  final x = r.map((e) => String.fromCharCodes(e)).join(' ');
  print(x);
}

Another way to code this.

final p1 = not(char($space)).right(anyChar());
final p2 = char($space).skipMany.right(p1.many1.sepBy(char($space).many1));

Or so. It's all the same code. It's a matter of taste.

final p1 = right(not(char($space)), anyChar());
final p2 = skipMany(char($space)).right(p1.many1.sepBy(char($space).many1));

And don't forget, it's strongly typed.
And besides, this framework loves to have you do the hard work yourself, using all your skills and knowledge in algorithms.
Nothing will work quickly and efficiently until you do it yourself.
And nevertheless, everything that you do not optimize will work with acceptable performance. Because the framework is fast enough.

This flexibility is its main advantage.
Combine (easy and simple) efficient self-written pure Dart code with what the framework offers and get exactly what you wanted and planned to get.
Basically, you may need to do this only in critical parts of the parser, but in general you could not do this.

суббота, 29 мая 2021 г. в 22:39:52 UTC+5, Randal L. Schwartz:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages