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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:24:57+00:00 2026-05-29T07:24:57+00:00

I realize this is a somewhat general question, but bear with me. Suppose that

  • 0

I realize this is a somewhat general question, but bear with me. Suppose that I have to insert a bunch of items into a data structure.

  • I can either insert them in one at a time, or in one giant batch.
  • The insert operation must take a lock on my data structure.
  • The insertion happens from one thread.
  • I don’t have any information about contention for the lock from other parts of the system.

Do you think it would be better to insert in batches or one-by-one or it doesn’t matter (…where “better” minimizes insertion time and lock hold time)?

  • 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-29T07:24:58+00:00Added an answer on May 29, 2026 at 7:24 am

    If only one thread has access to your data structure, then you don’t need the lock at all.

    If multiple threads need access then it’s a matter of how large is the “dosage”:

    • If you lock for each item, then you have very fine grain locking and multiple threads can probably update the list alternatively, allowing all of them to make progress. However, locking and unlocking many times will start to add up.
    • If you lock for the entire batch, then locking has negligible impact, but if the batch is large the other threads will be locked-out until you finish the entire update.
    • A trade-off would probably be to divide the large batch into a few smaller batches, such that you don’t take the lock too many times, yet all the threads are allowed to make some progress by having a chance to take the lock between batch updates.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize that the answer to this question is likely quite obvious (if somewhat
I realize this is a basic question but I have searched online, been to
I realize that this might be a duplicate question but this question is very
I realize this perhaps a naive question but still I cant figure out how
I realize this is more of a hardware question, but this is also very
I realize this is probably a hopelessly newbie question, but what is the difference
I realize this issue is somewhat trivial, but I'm interested in knowing the correct
So I realize this is an issue that seems to be somewhat contested. I've
I realize that the title may be somewhat confusing, so I apologize. Basically, this
(In Python 3.1) (Somewhat related to another question I asked , but this question

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.