In order to make recursive pattern matches run faster, its best to be tail-recursive. This avoids two costly steps: (1) initializing a new temporary scratch atomspace and (2) buying a new C++ stack frame.
The implementation is pretty small, although a bit tricky to understand: whenever the ContinuationLink is encountered, two c++ exceptions are thrown that return us back to the beginning, ready to do it again. No memleaks, no stack frames, just start it up again.
This is noticeably faster than before, like 10x or 100x faster (I didn't measure); its now less than an eyeblink instead of a heartbeat pause.
In order to make recursive pattern matches run faster, its best to be tail-recursive. This avoids two costly steps: (1) initializing a new temporary scratch atomspace and (2) buying a new C++ stack frame.
The implementation is pretty small, although a bit tricky to understand: whenever the ContinuationLink is encountered, two c++ exceptions are thrown that return us back to the beginning, ready to do it again. No memleaks, no stack frames, just start it up again.
This is noticeably faster than before, like 10x or 100x faster (I didn't measure); its now less than an eyeblink instead of a heartbeat pause.