question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

grammar files get opened an unnecessary amount of times, causing an enormous loading time when creating a parser

See original GitHub issue

it seems that, when using a FromPackageLoader object, a grammar file is opened and read from each time another grammar uses a rule that is imported from that former grammar. this means opening the same file over and over again, for each occurence of a rule contained in that file.

while this may not be noticeable for parsers that only use grammar files contained in the same directory (meaning no custom FromPackageLoader is necessary), it becomes highly problematic when using many FromPackageLoaders, as the time required to construct a parser goes up by an absurd amount.

by placing a print(resource_name) in the get_data() function of the python lib pkgutil.py, i was able to count how many times my grammar files were loaded each. for example, the common.lark grammar provided by lark gets opened 61 (!) times, one of my own grammars 25 times, another 16, etc.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:72 (72 by maintainers)

github_iconTop GitHub Comments

1reaction
MegaIngcommented, Sep 13, 2021

@ornariece I will create a PR, probably tomorrow. Now I gotta sleep. 😃

0reactions
erezshcommented, Sep 13, 2021

@MegaIng We can deduplicate rules in other, maybe better ways. For example, nested grammars can stand on their own, so that importing a.lark from two different grammars will result in the same rules and terminals (and the namespace will be just a, not nested)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improving the performance of an ANTLR parser - Strumenta
This happens because in this case the grammar is simple and the test file is large. This means that the ANTLR cache has...
Read more >
How I cut GTA Online loading times by 70% - Hacker News
I wonder if the same software quality caused other unnecessary in-game loading times. I felt that time spent playing GTA:O was about 60% ......
Read more >
FastParse 2.2.2 - GitHub Pages
FastParse is a Scala library for parsing strings and bytes into structured data. This lets you easily write a parser for any arbitrary...
Read more >
GNU make
Evaluate the arguments as makefile syntax. • Origin Function, Find where a variable got its value. • Flavor Function, Find out the flavor...
Read more >
RegEx match open tags except XHTML self-contained tags
... parse HTML. As I have answered in HTML-and-regex questions here so many times before, ... Every time you attempt to parse HTML...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found