clarity20 / tql

Terse Query Language
1 stars 0 forks source link

Optimize the parser and the SQL builder #43

Open clarity20 opened 5 years ago

clarity20 commented 5 years ago

Both of the above use shallow, almost linear chains of conditional branches. The code is noticeably slower as a result. Even though the speed is still tolerable, it is straightforward to see that stairsteps of nested tests would be an important optimization.

In the parser, we can group the conditions according to the character class of a token's leading character. In the SQL builder, we can implement a "token class" as a more general category than the token type and allocate another byte for it, to precede the token type in the markup. In both situations, we would want to make the common cases as fast as possible by positioning them high up in the branch hierarchy.