So far this has not come up as performance problem in any application.
Actually there are different scopes for variables. The context is just one one of them.
That query returns the OptiX variable object. You wouldn’t normally use that to read the values. The application should know what’s in them and would only need to write into them.
If you have so many individual variables at context level that you’re concerned about the performance to change their values, you’re doing it wrong. ;-)
After the initial setup of a renderer context the amount of variable changes between launches should be rather minimal. For example, in my progressive renderers exactly one variable is changed between contiguous launches: the iteration index for the accumulation of frames. Other variables are only changed during GUI interaction where performance is limited by the user.
Just checking, my most complex path tracer, which supports almost all of the Material Definition Language (MDL) 1.3 specs, uses 28 context global variables of which 9 are buffers.