3 ms·
I'm curious about a few things: - How many rules are there, and how complex do they get? It sounds pretty substantial if you're running into performance issues
by DylanSp 3y ago
I'm curious about a few things:
- How many rules are there, and how complex do they get? It sounds pretty substantial if you're running into performance issues (and/or you're working with highly demanding performance requirements)
- What do your rules look like? I'm having a bit of trouble understanding how you'd get recursion if there's just AND/OR operators. I can imagine an AST getting fairly big/deep, but the only way I can think of to get recursion would be if you're calling external functions multiple times, with different values over the course of processing a single request.
- secondcoming 3y agoHundreds at the moment, but it will need to scale to thousands. Complexity varies, it's usually a bunch of ORs but technically the complexity can be arbitrary as they're created by humans. Recursion comes from the AST structure. For example, for an AND operation it's essentially bool execute(ANDNode n) { return execute(n->left) && execute(n->right); } In reality it's the visitor pattern using variants. That's what I want to get away from.
- DylanSp 3y agoSo it sounds like the rules themselves aren't recursive, just your current strategy for evaluating them; is that correct? Given that, I'm more inclined towards the currently upvoted reply about translating them to JS/Lua and just calling eval(). [1] It'd be very simple and _should_ be fast enough, though you might need to worry a little bit about security (especially depending on whoever's providing the rule sets and how much validation there is around them). [1] https://news.ycombinator.com/item?id=37136272 https://news.ycombinator.com/item?id=37136272