Changed iteration over List from for-each to manual iteration.

For-Each loop creates Iterator object and uses hasNext and next methods, which are slower, than manual iteration. Also allocating Iterator object increases work for GC.

Forum post: https://hub.jmonkeyengine.org/t/iteration-over-list-performance-improvement/36250

See test 9 for more details: http://www.devahead.com/blog/2011/12/coding-for-performance-and-avoiding-garbage-collection-in-android/
define_list_fix
tiatin 9 years ago
parent e2b6c51730
commit 9c669547ab
  1. 7
      jme3-core/src/main/java/com/jme3/material/Material.java
  2. 7
      jme3-core/src/main/java/com/jme3/material/Technique.java

@ -750,7 +750,12 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
}
private int applyOverrides(Renderer renderer, Shader shader, List<MatParamOverride> overrides, int unit) {
for (MatParamOverride override : overrides) {
MatParamOverride override;
// manual iteration is used to avoid iterator allocation and to increase iteration performance
for (int i = 0, listSize = overrides.size(); i < listSize; i++) {
override = overrides.get(i);
VarType type = override.getVarType();
MatParam paramDef = def.getMaterialParam(override.getName());

@ -111,7 +111,12 @@ public final class Technique {
}
private void applyOverrides(DefineList defineList, List<MatParamOverride> overrides) {
for (MatParamOverride override : overrides) {
MatParamOverride override;
// manual iteration is used to avoid iterator allocation and to increase iteration performance
for (int i = 0, listSize = overrides.size(); i < listSize; i++) {
override = overrides.get(i);
if (!override.isEnabled()) {
continue;
}

Loading…
Cancel
Save