Update for Gurobi 9.0.1
As of Gurobi 9.0.1, string attributes are now cached when querying variables. Nevertheless, you should still avoid running code like this in the Cloud/Compute Server environment:
for name in names:
x = model.getVarByName(name)
Performance considerations for Gurobi 8.1 and earlier:
When solving models on a Compute Server (including Gurobi Instant Cloud), it is important to minimize the communication overhead, especially if the compute server is not on your local network. In particular, you should try to make as few calls to the server as possible when retrieving information.
For example, to collect solution values of all variables, you could call:
X_single = [v.X for v in m.getVars()] # time: 0.05s
which would retrieve the solutions one by one. However, the following achieves the same result in only one call:
X_all = m.getAttr('X', m.getVars()) # time: 0.05
In this example, you might not see any difference in time because Gurobi tries to efficiently cache server results (but this may not always be the case).
For variable names, there is a great difference because string values (like a variable name) are not cached:
Name_single = [v.VarName for v in m.getVars()] # time: 46.20
Name_all = m.getAttr('VarName', m.getVars()) # time: 0.05
They are not cached because they usually require a lot of memory (when used). Gurobi does not pay attention to these values internally but only stores them as part of the model. The reason you see a delay here is that every request for an attribute value results in a new request sent to the server.
The timings were produced with a latency of 35ms and a model with 1000 variables.