Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Compiling counted repetitions uses exponential memory #2

Open
lambda-fairy opened this issue Jan 10, 2014 · 0 comments
Open

Compiling counted repetitions uses exponential memory #2

lambda-fairy opened this issue Jan 10, 2014 · 0 comments

Comments

@lambda-fairy
Copy link
Owner

Currently, Rose compiles repetitions simply by unrolling them. For example, a{10} is compiled as the "match a" instruction repeated 10 times.

This can be dangerous. Consider what would happen if the user added a few more zeroes to the repeat count. Now, rather than allocating 10 instructions, the compiler will allocate 100 or 1000 or 100 000 instead. In fact, this is a case of exponential memory usage, since every extra digit multiplies the code size by 10.

There are two ways to solve this issue:

  • re2 -- place a hard limit on memory usage. If the compiler uses more than a specified amount (1 MB) it halts.
  • glennsl's engine -- rather than unrolling loops, track the repeat count in an extra register.

I prefer the re2 method, since it doesn't require changing the VM. The majority of repetitions are small anyway, so it's not worth gutting the implementation just to handle a corner case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant