influxdata / cron

A fast, zero-allocation cron parser in ragel and golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Investigate reducing the number of states in generated parser

adrian-thurston opened this issue · comments

Might be possible to reduce the number of states in the generated parser to get a smaller parser.go file. As discussed at the all-hands.

This discussion was with @docmerlin.

@adriandt that would be fantastic, if you have any tips for that it would be great.

A quick win would come from being more permissive in the grammar with day-of-week and month names, then afterwards verifying them using alternate means. If I use [a-zA-Z]+ for dowName and monthName I get a drop of states from 515 to 263.

You can treat it like a keyword lookup in a scanner. In C the fastest way to do that is using a constant hash table generator. Wondering now if go has that. They create super-optimized lookups. For example, if it can tell which word it is by peeking at the bytes in a certain order. I used to use gperf for this.

Next thing to look at will be those big actions. If they are repeated often the could be driving your final code size up. In general I try to avoid writing big actions unless I’m certain they would execute only once