-
Notifications
You must be signed in to change notification settings - Fork 401
Description
Context: This proposal partly replaces #4341, but has been written to stand on its own.
The basic steps for generating synthetic response bodies from vcl_synth{} currently are (as of 033d1d4):
- Set up a VSB and pass it as the specific pointer, ending up as
ctx->specific - call
vcl_synth{}, which calls one of theVRT_l_xyz_body()functions. These functions optionally clear the VSB and/or copy the argument(s) to it. - Copy the VSB contents into a stevedore object.
Via this code path, we end up making two copies of the arguments to VRT_l_xyz_body(). There is a similar code path to handle vcl_backend_error {}, which differs in that the second copy is to a stevedore object which potentially can be longer lived (represent a "synthetic cache object"), and is likely to outlive the scope of the backend request.
So there is optimization potential here to save two (for vcl_synth{}) and one (for vcl_backend_error{}) copies of the body data, respectively.
To optimize both cases, I propose to do the following:
- collect the
VRT_l_xyz_body()arguments in arrays of io vectors. The required data structure has already been proposed asVSCARABin Prepare Varnish-Cache for the age of AI #4209 - For
vcl_backend_error{}, copy the io vectors to the storage object, basically identical to now, but saving one copy - For
vcl_synth{}, implement a trivial stv_synth stevedore, which takes the arrays of io vectors via a private interface and later "outputs" them via the object iterator callback.
The proposed stv_synth is safe because, all arguments ever passed to VRT_l_xyz_body() have at least PRIV_TASK lifetime (see also #4269 for a similar optimization based on the same insight).
The net effect of this proposal, if implemented, is to save two memory copy operations for body data created in vcl_synth{} and save one memory copy operation for body data created in vcl_backend_error{}.