-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vcc: Teach HEADER symbols to accept constant strings #3768
base: master
Are you sure you want to change the base?
Conversation
This tracking was very approximate, leading to many constant expressions being considered variable. Instead of marking all expressions variable right away, we can keep track of expressions that are edited on top of a constant expression. If a variable expression is simply the edition of a constant expression, for example a constant STRING edited into a STRANDS, the variable one keeps track of its constant origins.
If the expression was successfully parsed, it is possible to define how to edit it, whether it is variable or constant. This allows vcc_Expr() call sites to pass edit strings instead of making calls to Fb() and intertwine them with INDENT adjustments.
Go one step further in the reuse of the expression edit syntax and have a proper "\v2" sequence to refer to the symbol on the RHS in the assign table.
Now that assignments parse expressions with their own edit string, there is no longer a problematic boundary in the middle of an LBODY_* enum.
Static strings are unfortunately copied into workspace simply because they don't belong to it. Since it is safe to reference a static string, or at the very least a string that is guaranteed to outlive a VCL transaction since in this case it has the same scope as the VCL shared object, we can bypass the regular STRANDS assignment. When a transaction runs out of workspace, fails and goes to vcl_synth, we don't want to fail again because of a static VCL assignment of the content-type and retry-after headers from the built-in VCL. Refs varnishcache#3765
And get rid of a trailing space in the generated C code.
I added cef6f00 to show that The general pattern is: - Fb(tl, 1, "BEFORE\n");
- tl->indent += INDENT;
- vcc_Expr(tl, FOO);
- tl->indent -= INDENT;
+ vcc_ExprEdit(tl, FOO, "BEFORE\v+\n\v1\v-AFTER\n", NULL);
ERRCHK(tl);
- Fb(tl, 1, "AFTER\n"); There may be other types of symbols that could benefit from a constant assignment, but HEADER symbols seem to be the only obvious ones with on one hand one less STRANDS detour and on the other hand one less workspace allocation. |
I came back here after we found agreement on #4269. I am not sure if I expressed my thoughts on this ticket clearly enough, so here is an attempt to make good on that. My understanding of the premise of this ticket is that when we have The additional idea I mentioned is that we can also optimize My hope was that, if we taught VCC to handle the So now my question is: Is it worth it? I can see that the optimization for VCL constants makes sense, in particular for avoiding out-of-workspace conditions on error paths, but the The other case which we have optimized with #4269 is "value assignments" like (This section might be going to far, please do not take it as a concrete proposal...) Another question is, if we are going to touch this area anyway, are there better options, still? One obvious idea would be to represent headers as struct hdnv {
unsigned namelen, valuelen; // 2, 3
const char *name; // "a: "
const char *value; // "foo"
} Compared to our Footnotes
|
The main generic aspect of the change is the refinement of constant expressions across "proxy" expressions. For example a "static literal" turned into a single-component STRANDS would track its constant parent expression and should in theory still be considered constant once turned back into a STRING. Any symbol can register expression edits for constant expressions (with the help of the assignment facility moving to actual expression edits) and at this point we are still in generic territory. It just so happens that only HEADER learns how to assign constant expressions.
I'm not too worried about this. The assignment facility can only know how to deal with
I didn't realize that, I thought it was only for the obj2resp setup. I need to have another look at #4269.
I'm not up for touching how we use this format to pack headers in storage. |
Just for completeness, again, I do not want to push this topic:
The storage representation would not change, it would still be "header: value". What would change is how our API looks at it. At the moment, it has a txt double pointer, the idea mentioned here is instead one "name" and one "value" pointer, both with a length. For headers from storage, the "value" pointer would point to the same string as "name". |
Static strings are unfortunately copied into workspace simply because
they don't belong to it. Since it is safe to reference a static string,
or at the very least a string that is guaranteed to outlive a VCL
transaction since in this case it has the same scope as the VCL shared
object, we can bypass the regular STRANDS assignment.
When a transaction runs out of workspace, fails and goes to vcl_synth,
we don't want to fail again because of a static VCL assignment of the
content-type and retry-after headers from the built-in VCL.
Refs #3765