multithreading - Performance hitches of some sort in a return or parameter (Java) -
i running complicated multithread java game, working exception of function. function, when called, approximately 0.01% of time, cause thread hitch of quarter of second. through series of debug lines , time measurements, it's absolutely down function (and 3 others it).
the usage of function provide light level of nearby block within voxel engine game. run when section of world updated, can happen alongside rendering.
please note:
- this function works accurately 100% of time intended function.
- this function causes thread hitch of approximately quarter second 0.01% of time.
- the variables not synchronized.
- the function never called more once @ time in program.
- all variables valid fields of larger, non-synchronized class.
- all variables integers.
- the array
light[][][]
byte[][][]
. - this method never called more once @ time, synchronized larger method on wide interval.
i'm pretty sure external synchronization not issue.
what part(s) of function may causing issue thread synchronization, cpu overuse, or stack filling, , how can go improving performance rid of these render hitches?
public byte nsleftlighting(int[] coords){ if(coords[0]<0)return 16; difx=chunkedx-chunks[coords[0]].x; difz=chunkedz-chunks[coords[0]].z; if(coords[1]==0){ if(-difx<=-(chunklimit)){return 16;} else if (-difx==0) { if(-difz>=0){ proz=0; specialz=-difz; }else{ specialz=difz-1; proz=1; } if(chunks[chunkxyid[1][proz][0][specialz]].loaded){ return chunks[chunkxyid[1][proz][0][specialz]].light[15][coords[2]][coords[3]]; } else{return 16;} } else { if(-difz>=0){ proz=0; specialz=-difz; }else{ specialz=difz-1; proz=1; } if(-difx>0){ prox=0; specialx=-difx-1; }else{ specialx=difx; prox=1; } if(chunks[chunkxyid[prox][proz][specialx][specialz]].loaded){ return chunks[chunkxyid[prox][proz][specialx][specialz]].light[15][coords[2]][coords[3]]; } else {return 16;} } } if(coords[1]>0){ return chunks[coords[0]].light[coords[1]-1][coords[2]][coords[3]]; } return 16; }
i don't see in here cause performance problem -- @ least not high variance. array accesses should extremely fast -- if 4 dimensional arrays. [[nice effort on that.]]
a quarter second not huge amount of time makes me wonder if profiler lying source of problem. may responding poorly multi-dimensional arrays or other attribute of method not apparent -- me @ least.
one possibility, remote, program swapped , these arrays pretty big. if aren't accessed there chance seeing io memory pages swapped in?
you commented using wall-clock timers determine routine takes 250ms. sure cpu executing method time period? thread contention issue taking on cpu in other part of program? can see if see cpu spikes every when method takes long time?
any chance seeing gc heap lock , it's affecting array accesses more other routines? can watch memory graphs see if see correlation? giving program more heap affect timing or frequency of problem? going more issue if running java <= 1.5.
Comments
Post a Comment