This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-16
Channels
- # adventofcode (93)
- # beginners (104)
- # boot (1)
- # cider (4)
- # cljsjs (2)
- # clojure (174)
- # clojure-austin (1)
- # clojure-greece (5)
- # clojure-spec (13)
- # clojure-uk (32)
- # clojurescript (15)
- # core-logic (13)
- # cursive (13)
- # data-science (8)
- # datomic (11)
- # duct (1)
- # fulcro (22)
- # instaparse (23)
- # jobs (1)
- # lein-figwheel (5)
- # off-topic (13)
- # onyx (13)
- # parinfer (1)
- # pedestal (19)
- # re-frame (33)
- # specter (26)
- # unrepl (22)
Hello. Why is my InstaParser so slow? 850ms vs 8ms hand-written Clojure: https://github.com/borkdude/aoc2017/blob/master/src/day16.clj#L119
How big is the input?
The input is this: https://github.com/borkdude/aoc2017/blob/master/resources/day16.txt
Here’s the grammar: https://github.com/borkdude/aoc2017/blob/master/src/day16.clj#L17
I mean, you're basically generating one string per character in a 40kb file. I'm not surprised it's slow.
And wrapping with vectors, etc
I had that before, but I wanted to transform the arguments to ints, that’s why I wrapped them later
Hmm yeah
I mean, it’s not really a problem, but just curious why or if I made a mistake in my grammar
I don't think you made a mistake like an ambiguity issue or anything
It's just really exercising the parser's dataflow overhead
I saw similar issues when trying to perf-tune @dave's Alda parser a while ago
Because his rules were like "if you see this single character, parse this other single character"
Instaparse does a lot of bookkeeping during a parse to make sure it magically works with weirdly recursive grammars, so for super low level parsers like this it doesn't exactly shine
(def parse2
(insta/parser
"<INPUT> = (INSTRUCTION <','>)+ INSTRUCTION
<INSTRUCTION> = SPIN | EXCHANGE | PARTNER
SPIN = <'s'> POSITION
EXCHANGE = <'x'> POSITION <'/'> POSITION
PARTNER = <'p'> PROGRAM <'/'> PROGRAM
<POSITION> = #'\\d\\d?'
<PROGRAM> = #'[a-p]'"))
No nesting of position and program, 800msJust curious, does anything improve if you change the first rule to INSTRUCTION (<','> INSTRUCTION)*
?