monora / rgl

RGL is a framework for graph data structures and algorithms in Ruby.
https://monora.github.io/rgl/
Other
415 stars 59 forks source link

calling require inside a mehtod is causing memory bloat if this method is called multiple times. #99

Closed asivasub14 closed 1 year ago

asivasub14 commented 1 year ago

https://github.com/monora/rgl/blob/8613828f285fae9e2c769188d86956f7e1a6275f/lib/rgl/traversal.rb#L120

Image from our calling the bfs_search_tree_from method internally through the RGL directed graph is indicating high memory for the require, is it possible to remove it and do once when this file is loaded? image

monora commented 1 year ago

That is bad news. Since I do not want to require rgl/adjacency unconditionally: Can you check if this would solve the problem:

unless defined?(DirectedAdjacencyGraph)
  require 'rgl/adjyceny'
end

Even better, you could do a PR with these changes.

asivasub14 commented 1 year ago

Sure, will test this and submit a PR. Just out of curiosity why we do not want to require unconditionally?

monora commented 1 year ago

I want to minimize dependencies. Only this method of the modul needs adjacency.

monora commented 1 year ago

Fixed by PR #100