如何在更短的时间内迭代大型 Java 整数列表?

use*_*271 5 java algorithm performance

int[] records = job.getTargetSearchIDs();
topology.applyMatcherSearchWeight(records);
int[] mIDs = topology.getMatcherIds();
SystemResponse[] sysResponse = new SystemResponse[mIDs.length];
Map<Integer, SearchCommand> mrCmdsMap = new HashMap<Integer, SearchCommand>();
Run Code Online (Sandbox Code Playgroud)

mID 的长度为 250,记录的长度为 750 万个整数。我希望这个循环在配备 8 核 Intel Xeon X5355 处理器、64 位 Linux (Ubuntu) 和 32 位 Java 的服务器上运行不到 3 秒。

for (long mID : mIDs) {
  List<Integer> recIDsToMatch = new LinkedList<Integer>();
  Matcher matcher = topology.getMatcherById(mID);

  for (long record : records) {
    if (matcher.getRange().isInRange(record))
      recIDsToMatch.add(record);
  }

  if (recIDsToMatch.size() > 0) {
    SearchCommand command = new SearchCommand(job.getMatchParameters(), 
      job.getRequestType(),
      job.getId(),
      job.getMatchParameters().getEngineProperties(),
      recIDsToMatch);

    command.setTimeout(searchTimeout, TimeUnit.SECONDS);
    mrCmdsMap.put(mID, command);
  }
}
Run Code Online (Sandbox Code Playgroud)

阅读此代码片段时,会想到哪些改进?可以进行哪些数据结构和/或算法改进?

Boh*_*ian 2

如果您拥有大型数据集并且想要速度和简单性,请考虑使用像Lucene这样的文本搜索引擎,它可以索引数百万个文档并在几毫秒内使用相当复杂的匹配参数检索命中。