ulfurinn / wongi-engine

A rule engine written in Ruby.
MIT License
484 stars 42 forks source link

Is there a safe way to clone the engine? (deep copy) #53

Open lauraeci opened 8 years ago

lauraeci commented 8 years ago

I'm looking at this gem duplicate

Duplicate.duplicate(@engine)

What I want to do is create a template wongi engine and reuse it over and over again. Originally I was loading all the rules in to one engine all at once but then the engine seems to be getting too big. So another approach I tried was to load the common rules into the engine once, then copy the engine and use the copy so that the engine is only looking for the most recent "target" facts for matching with all the common facts. Hopefully this makes it a smaller set as I noticed that the matching starts out very fast and then slows down considerably.

Let me know if that's something that makes sense to do. I'm not sure that the deep copy is working correctly because now I see duplicate matches. Since it seems like the engine is very complicated/recursive, not sure the deep copy is a good idea.

I would love to hear your thoughts on this.

Thanks! -Laura

ulfurinn commented 8 years ago

Since it seems like the engine is very complicated/recursive, not sure the deep copy is a good idea.

Exactly that. There are tons of cross-references between internal objects.

Have you tried using overlays?

Admittedly I've never looked into performance optimization. Maybe it's time.