ReactiveBayes / RxInfer.jl

Julia package for automated Bayesian inference on a factor graph with reactive message passing
MIT License
249 stars 24 forks source link

Inplace message passing #78

Open bartvanerp opened 1 year ago

bartvanerp commented 1 year ago

Not sure whether it should be mentioned here or in ReactiveMP.jl, but for certain applications it is highly beneficial to support inplace operations (rules, computations, basically everything). In my experiments I am running into the issue where memory consumption roughly blows up with 1GB per second, significantly slowing down the inference speed. Especially in the rxinference() function, where the same model gets used to process a stream of data it is very important to have these inplace operations to prevent memory from leaking away and to prevent the garbage collection from slowing down the inference speed.

bartvanerp commented 7 months ago

Encountered a similar issue today for a generic function and was thinking about the following to retain backwards compatibility

struct FunctionWithMemory{F <: Function, M} <: Function
    f :: F
    memory :: M
end
(f::FunctionWithMemory)(x...) = f.f(x..., f.memory)

There are probably some flaws with this approach, but might be nice as we then do not have to overhaul all rules at once.