SGFParser
SGFParser copied to clipboard
Speed Increases
The SGF parser is slllloooow.
Specifically...
SGF::Parser#next_character:
[email protected]? && @stream.sysread(1) is really slow. The stream methods are poor choices because they don’t get cached at all. You’d find exponential improvements in speed by reading the whole thing to a buffer at once, and then just slicing it or iterating over it.
SGF::Parser#parse_property
is really slow, due to the while loops in parse_comment, parse_multi_property and parse_generic_property. Please use built in string methods instead, they are much faster than your pure ruby implementation. Since you should now be reading to a buffer, you don’t need to go over ever character individually - expect huge speed ups.
SGF::Parser#still_inside_node?
steam methods AND while loop. lucky this doesn’t get called much.
Generally, reworking the parser to work with built-ins on a buffered read should do two things:
- immense speed ups
- no more issues with ]