Fastest way to get variable from 500 instances?

I need to fetch a varible from 500 instances. 500 instances is quite large number but can’t be reduced (which would make it faster).

What I try to do (but takes long time):

 String name = "";
 // ids is id from 500 instances
 HistoricVariableInstanceQuery query =  camunda.getHistoryService().createHistoricVariableInstanceQuery()
                 .processInstanceIdIn(ids);
 for (String id : ids) {
       HistoricVariableInstanceQuery hviq = query.processInstanceId(id);
       name = hviq.variableName("myNameVariable").singleResult().getValue().toString();

How to make it faster?