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

don't use exceptions to implement ismatch and trymatch #81

Closed
JeffBezanson opened this issue Jul 22, 2018 · 5 comments
Closed

don't use exceptions to implement ismatch and trymatch #81

JeffBezanson opened this issue Jul 22, 2018 · 5 comments

Comments

@JeffBezanson
Copy link

This is causing JuliaLang/julia#28221. At least for APIs that return a result instead of exposing MatchError, the package should use return values instead of exceptions.

@MikeInnes
Copy link
Member

Yeah this has always been a performance issue. I think we need a little Rust-style @try macro to make it simple to do the backtracking here without exceptions.

@cstjean
Copy link
Collaborator

cstjean commented Jul 23, 2018

Matching is essentially interpreted in MacroTools, right? I wonder how hard it would be to directly macroexpand patterns like foo(x_, 2) into if ex.head==:call && ex.args[1] == :foo && ... On Lisp had an implementation for Common Lisp.

@MikeInnes
Copy link
Member

Right, the core matching machinery is a function of both a template and an expression to match. We could do something smarter there, but it essentially means having two separate implementations of matching, and the performance benefit will not likely be that great. Really it's just the use of throw/catch that's adding the extra order of magnitude hit here.

@cstjean
Copy link
Collaborator

cstjean commented Nov 2, 2018

it essentially means having two separate implementations of matching

Why? If we had a compiled version, we could drop the interpreted one. Are you aware of any code that modifies the pattern and calls match directly?

the performance benefit will not likely be that great

I wonder about that. MacroTools is pretty ubiquitous these days.

@MikeInnes
Copy link
Member

Perhaps. At the very least it's part of the API now (you can also splice runtime expressions into the pattern). But that might be infrequently-used enough that we can just get rid of it.

I could see us getting something like 2x better with a compiled version, especially on simple cases like that one. Once you get to slurping and such though, there's always going to be quite a lot of dynamic dispatch, backtracking etc. and it's not that likely to have a noticeable impact of precompilation.

I'm happy to be proven wrong though. We could always have a very simple compiler that bails out to the interpreter, and then gradually expand that and remove the current implementation as we go along – just needs someone willing to hack on it.

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

3 participants