2

I'd like to write some lightning-fast functions for analyzing LaTeX code. Because they could involve a lot of complicated processing of large documents, I don't know whether it's a good idea to write them completely in Lisp or not. How fast is byte-compiled Lisp compared to C, and how intensive does the processing have to be for the user to notice a difference?


Specifically, I'm trying to implement better functions for finding certain types of errors -- for example, neither show-paren-mode nor smartparens-latex are smart enough to notice that \left and \right are brackets that must match with another \left or \right. These programs also don't know that there are features brackets can't match across (so if it encounters one of these features, which will have to be defined a complicated way since it's environment-dependent), it should report a paren mismatch.

Because of the potential complexity of the code (parsing LaTeX can depend on the environment in complicated ways) and the fact that it has to be fast enough that the user won't notice a delay when, for example, they move the cursor over a parenthesis, I'm concerned about optimizing the code, and I want to know whether I can get away with writing careful Lisp or if it would be smarter to implement one or more primitives to help with the grunt-work.

closed as too broad by lunaryorn, Drew, zck, user2699, Gilles Dec 19 '15 at 19:10

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Are you sure you don't want to swap the contestants in the title? I rarely see claims about languages performing better than C and when I do, the tests feature abysmal C code... – wasamasa Dec 18 '15 at 22:08
  • 2
    It's not like you need to do a full implementation in both, a suitable prototype representing the workload you envision shall suffice. That being said, most of the time you won't need that level of sophistication and writing your code in elisp is fine. – wasamasa Dec 18 '15 at 22:27
  • 2
    I've seen benchmarking that showed that Common Lisp can be faster than C. It might be worthwhile to find that (I'll see if I can chase it up) and rewrite the CL functions in Elisp, just to see how that compares. – Joe Corneli Dec 18 '15 at 23:04
  • 1
    Your specific example can be implemented in smartparens btw, see its HTML tag or ruby block matching support for instance. Newer Emacs versions support the latter example in show-paren-mode as well. – wasamasa Dec 18 '15 at 23:16
  • 1
    Oh, I found the blog post I mentioned with the Wayback Machine. – Joe Corneli Dec 18 '15 at 23:35