Jacek Caban (@jacek) commented about dlls/vbscript/interp.c:
exec.vars = NULL; }
+ /* For global-scope code (ParseScriptText), resolve compile-time variable + * indices to pointers into ScriptDisp->global_vars[]. This allows OP_local + * and OP_assign_local to access global Dim variables by index instead of + * doing string-based lookup_identifier() at runtime. exec_global_code() + * has already registered all Dim variables into global_vars before this. */
The shadowing problem seems a bit more complicated than that. For example, when a named item is available, both it and a global variable may shadow the identifier. We may also be shadowed by a variable from a user-supplied `IDispatch`, in which case we do not have such a pointer reference at all. Such an `IDispatch` may have a mutable property set, which means it may start shadowing during execution. I would expect native vbscript to do some caching anyway, but I do not know how without testing. Perhaps, for example, it performs the lookup on demand and caches the result? This way, we would not pay the cost for unused identifiers. In jscript, the optimization is effectively disabled for global code in practice (`base_scope` is not set for global code, causing it to fall back to string lookup). Maybe that would be good enough for your use case as well? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10515#note_136524