Generate faster object code using the naked reference template
# Final Release Note The compiler detects certain patterns of normal global variable references and generates the faster [naked reference](https://docs.yottadb.com/ProgrammersGuide/langfeat.html#naked-references) object code, including some cases where M syntax does not allow for naked references. Specifically: - Consecutive references where subsequent references could be replaced by a naked reference, as long as the subscripts are constants or unsubscripted local variables, and there is no intervening command that modifies any local variables, e.g., `SET ^X(y,1)=2 WRITE ^X(y,1)`. - References with a changing number of subscripts, e.g., `SET ^X(1)=1,^X(1,2)=2`. - Arbitrary expressions used as the last subscript, e.g., `SET ^X(y,1)=2,a=-2 WRITE ^X(1,@("a+3"))`. The generated code and runtime system ensure correct behavior of the application code even when there is an intervening command that transfers control between the initial and subsequent references, e.g., handling a [MUPIP INTRPT](https://docs.yottadb.com/AdminOpsGuide/dbmgmt.html#intrpt) signal. Previously these patterns of global variable references generated normal object code for global variable references. [#665] [#1177] # Description Todo list --------- - [x] Optimize across line breaks, even with `-line_entry`: https://gitlab.com/YottaDB/DB/YDB/-/issues/665#note_2441017980. - [ ] Optimize FOR loops: bullets 3. and 5. of https://gitlab.com/YottaDB/DB/YDB/-/issues/665#note_2326164647 - [ ] Naked references with multiple subscripts: `^(1,2)` (done in https://gitlab.com/jyn514/YDB/-/tree/665-manual-naked-multiple?ref_type=heads) - [ ] Local variables used as subscripts: `SET ^x(y,1)=1 WRITE ^x(y,1)` - [ ] This needs to consider that $ZINTERRUPT can change locals. See https://gitlab.com/YottaDB/DB/YDB/-/merge_requests/1636#note_2445849237. - [x] Accesses with a changing number of subscripts: `SET ^x(1)=1,^x(1,2)=2` - [x] Arbitrary expressions used as the last subscript: `^x(1,@("a2+3"))`. Needed for bullet 3 of https://gitlab.com/YottaDB/DB/YDB/-/issues/665#note_2326164647. - [ ] Accesses where subscripts are only partially preserved: `SET ^x(1,2,3)=1,^x(1,4)`. Note there is no syntax-level M equivalent of this optimization (because `^(4)` would mean `^x(1,2,4)`, not `^x(1,4)`). But because we have access to the runtime, it's possible. (done in https://gitlab.com/jyn514/YDB/-/tree/665-manual-naked-multiple?ref_type=heads) Original issue description -------------------------- In code that is to be maintained by human beings, [naked references](https://docs.yottadb.com/ProgrammersGuide/langfeat.html#naked-references) are generally frowned upon as being error-prone. However, within a single line, when the YottaDB code generator finds consecutive accesses to the same global variable, it can generate naked reference code for second and subsequent accesses. The following shows the performance impact of naked references: ```m YDB>for i=1:1:1E6 set ^x(i)=$random(1E9) YDB>for j=1:1:3 xecute "set start=$zut for i=1:1:1E6 if $data(^x(i))" write $zut-start," " 182916 145762 142878 YDB>for j=1:1:3 xecute "set start=$zut for i=1:1:1E6 if $data(^(i))" write $zut-start," " 160086 124300 125072 YDB> ``` # Draft Release Note Application code with consecutive references to the same global variable runs slightly faster. [#665]
issue