-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax using with_prototype leaks memory #2699
Comments
It would appear you've got a loop of:
When you use It may seem obvious to you that the above recursion should use the same copy of built-in-fn, but it is also easy to come up with a chain that is not so obvious, such as one of the intermediate context having its own with_prototype. Then you'd need to create a new copy of each context with both This is why I say a general solution is not "simple". However, in your context it isn't obvious to me that you even should be using |
@wbond thanks for the quick reply. You are correct about the misuse of Note that, despite the recursion, Luigi highlighting would always terminate in theory. I was not aware that the syntax definition is pre-compiled in a manner that prevents recursion. While your implementation is proprietary, if there's any chance you're compiling the syntax to a DFA, have you considered making |
We likely won't offer the ability to add an arbitrary number of rules at run-time for performance sake, but the existing |
I'd say limiting to something like 32 and de-duplicating rules (so that multiple encounters of the same |
Run time rules require Oniguruma, the fallback (read slow) regex engine, because our optimized regex engine sacrifices compile time for improved run time performance. Additionally, the nature of |
I see. You could theoretically keep multiple compiled versions of the syntax (with and without Just out of curiosity, approximately how many times slower is matching with Oniguruma compared to using the optimising compiler? |
I believe in the past we've seen improvements of 30-50%, although I may be remembering incorrectly. There are probably some old comments on PRs related to sublimehq/Packages#481. |
@wbond ah, so the optimising compiler also uses backtracking? Maybe it'd be worthwhile implementing optimisations for a simpler set of regular expressions. |
No
Jon has definitely read that (he is the author of Sublime's custom regex engine) and our engine even has some unique elements that aren't implemented by other engines. |
Interesting. From what I know from the linked article, I'd either expect your custom engine to run orders of magnitude faster than Oniguruma but not support backreferences, or support backreferences, use backtracking, and perform more or less equally (with the added benefit of possible compile-time optimisations on the regex). There must be a graph search approach well-suited for regex matching that I am unaware of; any pointers would be appreciated. I understand if such information is considered a trade secret, however. |
The orders of magnitude you're thinking of only become relevant if there is a lot of backtracking to begin with, e.g. patterns with many quantifiers. Most patterns in syntax definitions do not rely on these, so the overall performance gain for these patterns will be limited but noticeable. |
@keith-hall while my syntax definition shouldn't have used @FichteFoll good point. So does your regex engine support backreferences? |
Build 4075 adds protection to prevent recursion when using |
Description
Using
with_prototype
in a syntax definition causes a severe memory leak very similar to #1288 (I have been instructed to open a new issue for this one).You can download the leaky syntax definition on Pastebin.
Steps to reproduce
# BUG: ...
Expected behavior
The editor wouldn't leak memory.
Actual behavior
Leaks at over 0.5 GB/s on my machine.
Environment
4.20.6-arch1-1-ARCH
The text was updated successfully, but these errors were encountered: