Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7605611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:12:38+00:00 2026-05-31T00:12:38+00:00

I am running a complicated multithread java game, which is working perfectly with the

  • 0

I am running a complicated multithread java game, which is working perfectly with the exception of this function. This function, when called, approximately 0.01% of the time, will cause a thread hitch of a quarter of second. Through a series of debug lines and time measurements, it’s absolutely down to this function (and three others almost exactly like it).

The usage of this function is to provide the light level of a nearby block within a voxel engine game. It is only run when a section of the world is updated, which can happen alongside rendering.

Please note:

  • This function works accurately 100% of the time for its intended function.
  • This function causes a thread hitch of approximately a quarter second 0.01% of the time.
  • The variables are not synchronized.
  • The function is never called more than once at a time in the program.
  • All variables are valid fields of a larger, non-synchronized class.
  • All variables are integers.
  • The array light[][][] is a byte[][][].
  • This method is never called more than once at a time, as it is synchronized by a larger method on a wide interval.

I’m pretty sure external synchronization is not the issue.

What part(s) of this function may be causing an issue with thread synchronization, CPU overuse, or stack filling, and how can I go about improving performance to get 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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:12:40+00:00Added an answer on May 31, 2026 at 12:12 am

    I don’t see anything in here that would cause a performance problem — at least not with that high a variance. Array accesses should be extremely fast — even if they are 4 dimensional arrays. [[Nice effort on that.]]

    A quarter second is not a huge amount of time which makes me wonder if the profiler is lying to you about the source of the problem. It may be responding poorly to the multi-dimensional arrays or some other attribute of this method that is not immediately apparent — to me at least.

    One possibility, however remote, is that your program is swapped and these arrays are pretty big. If they aren’t accessed very often is there any chance you are seeing some IO as some memory pages are swapped in?

    You commented that you are using wall-clock timers to determine that the routine takes 250ms. Are you sure that the CPU was actually executing that method for that time period? Could this be a thread contention issue that is taking over CPU in some other part of the program? Can you see if you see CPU spikes every so often when this method takes a long time?

    Any chance you are seeing a GC heap lock and it’s affecting the array accesses more than other routines? Can you watch the memory graphs to see if you see a correlation? Does giving the program more heap affect the timing or the frequency of the problem? This is going to be more an issue if you are running Java <= 1.5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running a ServiceHost with a single contract is working fine like this: servicehost =
this is my first posted question. I have a fairly complicated OQL query which
Running FxCop on my code, I get this warning: Microsoft.Maintainability : 'FooBar.ctor is coupled
Running ipconfig /all shows a Teredo Tunneling Pseudo-Interface. What is that? Does this have
I have a semi-complicated problem and hoping that someone here will be able to
I have an application running in IIS which connects to a SQL Server 2008
This might be a bit complicated, but bear with me. I have a Windows
I have a somewhat complicated assortment of tables for which I need to do
This is a question about some stored procedures running on MSSQL 8 (I think
I'm using subsonic 2.2 in an app. I'm running a little complicated query in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.