Skip to content
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

Has anyone looked into performance? #269

Closed
stevedefazio opened this issue Oct 8, 2021 · 2 comments
Closed

Has anyone looked into performance? #269

stevedefazio opened this issue Oct 8, 2021 · 2 comments

Comments

@stevedefazio
Copy link

Disclaimer: I have yet to run my code in a production type setting, so don't have a good sense of if this is a real problem or not yet.

But thinking about (for comparison) the Java Pattern class, for regular expressions. By calling Pattern.compile, you ensure that you compile your pattern only once, even if you do many comparisons.

With this library if I were to call the same method with an Expression in it a thousand times with different numbers, I think I'd effectively be recompiling that expression a thousand times.

So my question is, do you think there might be an opportunity to "compile" expressions beforehand, to save effort from repeated calls and would it be worthwhile?

The eval() method could be called by compile. Later, when eval is called on the compiled Expression, the variables could simply be inserted into the appropriate locations, without reparsing the whole string.

@uklimaschewski
Copy link
Collaborator

Hi, if you look into the eval() method, you will see that it is exactly behaving like you described.
If the pattern has been 'compiled' before (converted to a RPN list of tokens using the shunting yard algorithm), the existing RPN list will be used. You can then change the variable assignments and call eval() again, which will use the previously 'compiled' expression with a new result.

@stevedefazio
Copy link
Author

Ah, my mistake for misunderstanding! Thank you so much, this is a great library!

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

No branches or pull requests

2 participants