vectordotdev / vrl

Vector Remap Language
Mozilla Public License 2.0
123 stars 56 forks source link

Add function memoization #137

Open JeanMertz opened 3 years ago

JeanMertz commented 3 years ago

There have been several situations in which a VRL function has relatively slow runtime performance, but the operation it performs results in a value that is relatively static.

see: https://github.com/timberio/vector/pull/6141

I propose we add a “function cache” to the VRL runtime.

The idea is this:

There are still some things to work out here, but it seems a valuable property to have in the runtime.

bruceg commented 3 years ago

Memoization like this makes sense for really slow functions, but we should be careful of two things:

  1. Hashing parameters to access the cached value and cloning to store a new value also has a cost, so this should probably be limited to certain functions that are known to be slow.
  2. Make sure there is at least consideration for excluding functions that are not const.
fpytloun commented 4 months ago

I am also very interested in this one. Any time soon? 🙂

pront commented 4 months ago

I am also very interested in this one. Any time soon? 🙂

We do not have capacity in the near future. This sounds like a medium size project and will some thought on how to integrate this in the VRL runtime.

Contributions are always welcome.