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 8167967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:22:20+00:00 2026-06-06T20:22:20+00:00

Background: I hope my question is not too vague. I will try and explain

  • 0

Background:
I hope my question is not too vague. I will try and explain as much as possible, and cannot post too much code, as the affected method is very complex and lengthy. So my problem is that I am trying to speed up processing with multiple threads. The application is for lighting in my 2D game engine, where I draw black rectangles of different transparency levels on top om my scene (which is currently causing lag).

The first step for me was to batch adjacent rectangles of equal light level together to reduce some rendering work. This worked out fine (perhaps it can be done better, but not the point now), and now I also implemented a crude threading system, which will each batch together lighting for a separate portion of the screen.

Crux of my question: While analyzing the timing of the particular batching method described above (for different number of threads working on separate, disjoint data sets), I noticed some odd spikes. Previously, when working with one thread, the method took about 12ms to execute, with odd jumps to 15ms. I didn’t think much of it. When processing with 2 or 3 threads however, I get more or less 4~5ms, with jumps to 10ms, and sometimes even as high as 20ms.

Now I realize that it is not possible for anyone to tell what the cause could be without inspecting my code, so I do not expect that. Rather, I am trying to draw some conclusions and wish to confirm them now. As stated before, each thread does work on portions of my data set, completely disjoint from one another (they do not overlap). However, the entry point to the data array is through the same method of the same instance of a particular class. So the threads all access the same array (yet separate portions of it – and for this reason I also don’t use any locks) through the same method. Could this cause unexpected slow downs?

Or is it perhaps normal behavior for threads to act in this way (with execution time varying to more than double of the norm)? As another note, I create all threads at the moment I need them, and let them run to completion.

The accessing method for the data set:

public short GetLightLevelAt(int x, int y)
{
   if (inLightingBounds(x, y))
   {
      return lightData[x, y];
   }
   else
   {
      return GuessLightLevelAt(x,y); //This won't ever happen currently, guaranteed
   }
}
  • 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-06-06T20:22:21+00:00Added an answer on June 6, 2026 at 8:22 pm

    In your case, it probably has to do with Garbage Collection or Context Switching as mentioned above, due to the high spikes.

    However, running multi-threading over the same array may still exhibit slowdowns due to false sharing. (even with non-overlapping partitions)

    For instance, the following code could have a problem with false sharing:

    int[] array = new int[100000];
    int a = 1;
    int b = 0;
    
    //The following loops run concurrently
    
    //Thread A
    for( int i = 0; i < 50000; i++ )
        array[i] = a;
    
    //Thread B
    for( int j = 50000; j < 100000; j++ )
        array[j] = b;
    

    The false sharing occurs since int a and b are declared next to each other, and quite likely are on the same cache line as each other.

    If run concurrently, this code could exhibit no speed-up at all, and possibly a slow-down.

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

Sidebar

Related Questions

I hope that this question will not have the same luck with this one
I hope this question is considered appropriate for stackoverflow. If not, I'll remove the
I hope that this question has not been asked elsewhere, but I'm having difficulty
Background I admit, this question stems from an ultimate lack of deep understanding of
Background: I'm writing a 'standard' (nothing special) web application in Ruby (not Rails) and
Background I'm not new to programming, however I am when it comes to handling
Background: This is a follow-up question to this thread about handling EINTR for system
I am not sure if this is the write place to ask the question.
Hey guys. I'm not much of a programmer, but still need to do some
I hope this question is considered programing related. I've been learning and using .NET

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.