Skip to content

Commit

Permalink
Pre allocate threadpool, with size of 2/3rds numProcessors
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 committed Jan 1, 2020
1 parent dad378e commit 4b56f78
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mc_version=1.7.10
forge_version=10.13.4.1614-1.7.10
ccl_version=1.1.3.138
ccc_version=1.0.7.+
mod_version=2.0.0-pre-5-GTNH
mod_version=2.0.0-pre-7-GTNH
1 change: 1 addition & 0 deletions resources/assets/nei/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ nei.options.wbutton.tip.0=Using global settings
nei.options.wbutton.tip.1=Overriding global setting

nei.options.keys=KeyBindings
nei.options.keys.showenchant=Show Enchant
nei.options.keys.gui=Inventory
nei.options.keys.gui.recipe=Recipe
nei.options.keys.gui.usage=Usage
Expand Down
31 changes: 24 additions & 7 deletions src/codechicken/nei/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.regex.Pattern;

public class ItemList
Expand Down Expand Up @@ -227,22 +229,37 @@ public void execute() {
}
};

public static ForkJoinPool getPool(int poolSize) {
if(poolSize < 1)
poolSize = 1;

return new ForkJoinPool(poolSize);
}

public static final int numProcessors = Runtime.getRuntime().availableProcessors();
public static ForkJoinPool forkJoinPool = getPool(numProcessors * 2 / 3);

public static final RestartableTask updateFilter = new RestartableTask("NEI Item Filtering")
{
@Override
public void execute() {
ArrayList<ItemStack> filtered = new ArrayList<>();
ItemFilter filter = getItemListFilter();

items.parallelStream().forEach(item -> {
if (interrupted()) return;
try {
ItemList.forkJoinPool.submit(() -> items.parallelStream().forEach(item -> {
if (interrupted()) return;

if(filter.matches(item)) {
synchronized (filtered){
filtered.add(item);
if(filter.matches(item)) {
synchronized (filtered){
filtered.add(item);
}
}
}
});
})).get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
stop();
}

if(interrupted()) return;
ItemSorter.sort(filtered);
Expand Down

0 comments on commit 4b56f78

Please sign in to comment.