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

  • Home
  • SEARCH
  • 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 7782801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:39:13+00:00 2026-06-01T19:39:13+00:00

I’ve got a lot of objects, every one has some tags, which are stored

  • 0

I’ve got a lot of objects, every one has some tags, which are stored in NSDictionary. I’ve also got a loop, in which I’m iterating through all objects and do some stuff depending on object’s tags. Method objectForKey: worsens performance a lot, if there are too many calls of it. How can I improve the performance? I’ve tried, for example, set “strong” instead of “copy” into @property, but that did not solve problem. Thanks!

EDITED:

Here is some kind of code, it is much more simple than the one in my project, of course. The Profiler says that the hot spots are in objectForKey:, not in doSomeStuff:. Can It be because of amount of its calls? Tags have got few objects, about 10 for each object, but the amount of objects is rather large

.h:

@interface MyObject : NSObject

@property (nonatomic, readwrite, strong/*copy*/  ) NSDictionary *tags;

-(void)doSomeStuff;

@end

.m:

@implementation MyObject
{
    NSDictionary *tags; // about 10 values for each object
}


-(NSDictionary *)tags
{
    return tags;
}

-(void)setTags:(NSDictionary *)newTags
{
    tags = [newTags copy];
}

-(void)doSomeStuff;

@end

using:

NSArray *objects = ... // a lot of items, > 1000
NSArray *rules = ... // NSArray of objects with property NSArray* Strings, about 50 strings

for (MyObject *object in objects)
{
    for (NSArray *rule in rules)
    {
        for (NSString *ruleString in rule.Strings)
        {
            // there is a more complicated check in my project, so you may imagine that there are 10 calls of objectForKey:, with different keys
            if ([object objectForKey:ruleString] isEqualToString:@"yes"])
            {
                [object doSomeStuff];
            }
        }
    }
}
  • 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-01T19:39:15+00:00Added an answer on June 1, 2026 at 7:39 pm

    If objectForKey is slow, your best bet might well be to create a custom (more efficient) implementation of hash for the objects that you’re adding. It’s possible that the default implementation is creating lots of clashes which is likely to affect performance.

    Having said that, you don’t say how many objects you’re adding, what you’re doing with them or what environment you’re using. It’s difficult to say much more than guess. In general, NSDictionary is pretty efficient.

    Edit: To clarify based on the extra information you added… I don’t think this is about improving the performance of NSDictionary. Given your numbers, you’re calling objectForKey: over half a million times; of course this is going to be the most demanding operation. You need to think about optimising your algorithm (pre-computing?) rather than trying to making something that’s already quick very slightly faster.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.