oracle-samples / clara-rules

Forward-chaining rules in Clojure(Script)
http://www.clara-rules.org
Apache License 2.0
1.19k stars 110 forks source link

Memory use in CLJS #125

Open jpthomson opened 8 years ago

jpthomson commented 8 years ago

Hey all,

More of an open ended question for anyone use played with Clara in Clojurescript. I'm seeing large spikes in memory footprint when assembling the session, specifically in building the beta network.

To give you an idea, we currently have 20 rules, with between 2 and 10 LHS clauses, each with two conditionals. This results in a memory spike of around 400mb, much of which seems to get garbage collected.

Does this seem reasonable? Any pointers of what specifically could be allocating this memory?

Many thanks in advance.

Jonathan

rbrush commented 8 years ago

400mb sounds bad to me, but to be honest everything I do with Clara is in the JVM so I don't have a great idea of what memory patterns look like in web browsers. Are you able to do some memory profiling to see if anything terrible pops up? It might be worth seeing if the latest version of ClojureScript itself helps in any way as well.

I'm not sure what the state of the art is in profiling ClojureScript (I tend to use YourKit for ordinary Clojure), so it might be necessary to ask around the ClojureScript Google group for profiling suggestions.

devn commented 8 years ago

@jpthomson Out of curiosity: how many facts are being inserted into the session?

jpthomson commented 8 years ago

@devn the memory spike happens before any facts are inserted, weirdly. The client loads data progressively from the server and I don't see memory increasing noticeably as that happens.

@rbrush Thanks, I'll do some digging and report back!

rbrush commented 8 years ago

@jpthomson Cool, let me know if you find anything interesting. It's possible the way we're constructing the rete network for ClojureScript is inefficient -- it basically just generates a single, large evaluation tree for the network -- but that can be broken up if it causes problems.

I've also noticed that web browsers will sometimes just grab memory if it's available (it's there to be used!), which can really inflate the reported usage even though that memory can be quickly freed. Right now my gmail tab is consuming 380 MB by itself.

That all said, I'd love to have more diligence given to the ClojureScript version of Clara. I'm comfortable with the performance of the Clojure version (I use it heavily in production), but having more ClojureScript users interested in contributing to that would be great.

jiangts commented 7 years ago

Any updates regarding the cljs memory footprint? I'm writing a cljs backend on node.js and would like to use clara rules.

rbrush commented 7 years ago

I'm afraid I don't have any news on the ClojureScript front. We use Clara heavily in production, but only on the JVM, and therefore haven't had a good workload to tune the CLJS version. I'm also not the most proficient at optimizing Javascript-based platforms, but would be happy to work with anyone interested in digging into this.