You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is often a mismatch between the data format wirefilter expects and the raw data available in the application. This requires conversion, and both the conversion process and the allocation/deallocation of the transformed data incur overhead.
structRequest<'a>{url:&'a[u8],// raw header dataheader:HashMap<&'a[u8],Vec<&'a[u8]>>,// wirefilter header datawirefilter_header:TypedMap<'a,TypedArray<'a,Bytes<'a>>>,}
Although ast.uses() can filter out variables that are not referenced by the expression, it does not address the issue of short-circuit evaluation. For instance:
Here, the header variable appears in the expression and therefore will be included by ast.uses(), but it may never actually be evaluated (because the first condition short-circuits). In this case, the conversion for header is wasted effort.
Workarounds (and their limitations)
One idea is to replace the variable with a function, so expressions could use get_header()["foo"][*] instead of header["foo"][*]. This would defer the conversion until the function is actually called. Unfortunately, wirefilter functions currently can only return a fixed value and are unable to pull data from context or user_data to construct a result dynamically, making this approach infeasible.
A more comprehensive approach would be to add something akin to Python's property mechanism: a variable that looks like an ordinary field from the expression's perspective, but is actually backed by a function that can pull the necessary context at evaluation time to construct its return value on the fly.
Cloudflare's internal use cases are fairly similar to the example above, I suspect you've encountered the same kind of overhead and would love to hear how you approach this optimization internally.
Hi! Thank you for taking the time to look into wirefilter.
Cloudflare's internal use cases are fairly similar to the example above, I suspect you've encountered the same kind of overhead and would love to hear how you approach this optimization internally.
We rely on a custom compiler to implement a variety of optimisations etc However the problem you are facing is not a problem we are facing because the rulesets engine is used in many places while processing a request that just computing the fields needed in time before the execution of a ruleset is enough and we would not gain anything by avoiding computing a value because most/all values would be computed somehow anyway by another rule.
Activity
virusdefender commentedon Sep 18, 2026
I gave it a try and wrote a demo. Anyone with similar needs can refer to it:
https://github.com/virusdefender/wirefilter/tree/lazy
Add lazy field evaluation with reusable external caches
marmeladema commentedon Sep 19, 2026
Hi! Thank you for taking the time to look into wirefilter.
We rely on a custom compiler to implement a variety of optimisations etc However the problem you are facing is not a problem we are facing because the rulesets engine is used in many places while processing a request that just computing the fields needed in time before the execution of a ruleset is enough and we would not gain anything by avoiding computing a value because most/all values would be computed somehow anyway by another rule.
marmeladema commentedon Nov 14, 2026
@virusdefender we are investigating a more involved solution in #210