200ok-ch / org-parser

org-parser is a parser for the Org mode markup language for Emacs.
GNU Affero General Public License v3.0
316 stars 15 forks source link

lein test takes more than 2 minutes to finish #37

Closed schoettl closed 3 years ago

schoettl commented 3 years ago

lein test (specifically parser-test) takes more than 2,5 minutes to finish.

Is there a possibility to speed this up? Even in Emacs with cider and a connected repl, running this tests takes minutes.

munen commented 3 years ago

@schoettl Very good point. Thanks for pointing us at that! We're looking into it. So far I can say:

munen commented 3 years ago

@schoettl All good now. lein test is back to running in <6s on my machine. Thanks for the bug report :pray:

schoettl commented 3 years ago

Wow, thanks for fixing it! I don't understand the fix at all :D I really have to learn basics of clojure some day ^^

munen commented 3 years ago

@schoettl Sure, you’re welcome^^

The fix was quite trivial after we saw what’s slow. We started with benchmarking all tests (the reverted commit yields the comment above) and saw that all parser tests are slow now. Then, we checked what the last commit with fast tests were by bisecting. We looked at the diff and saw that only code, no EBNF was changed. Then, we used visualvm to profile the codebase and found the culprit. All time was spent in one function.

The change introduced on the commit was to use a function with defn vs. a static car with def. One gets evaluated on every call, one only once. There’s no need to parse the EBNF every time, once on startup is quite enough, so the right way is a def.