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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:34:29+00:00 2026-05-26T21:34:29+00:00

This is a general objective-c / iPhone question: If I have a large method,

  • 0

This is a general objective-c / iPhone question:

If I have a large method, is it better to create a single class and call the method from other classes or just re-write the method when I need it in each new class? I’m asking not from a code reading perspective, but from an iPhone performance perspective. Does the compiler care? Does anyone have evidence of singleton subclassing being significantly faster?

  • 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-26T21:34:30+00:00Added an answer on May 26, 2026 at 9:34 pm

    There is no satisfactory generalized answer, whether a singleton is faster than multiple instances.

    I’ll talk about shared instances (not singletons).

    You can make some higher level generalizations with shared instances.

    If your object has no mutable or thread critical state, then you may reduce the number of objects you create by sharing that instance. In that case, you will reduce the number of objects you create (whether that should be a concern in your particular case is unknown).

    Similarly, if you have found a problem, you can often reconsider class designs to reuse and share appropriately for the problem you have observed. This would often consist of dividing a large class’ mutable state from its immutable state, and sharing the immutable pieces among transactions. This technique is often reserved for more advanced problems, and might happen a few times in a moderately complex iPhone app, but is not often a problem people consider worthy of correction in small apps as the developer did not consider it an issue worth their time.

    If your objects have state or must operate in a thread safe manner, then you may want to appropriately reconsider what needs to be shared, and what does not need to be shared. This also varies wildly by how your program executes.

    So, let’s say we have a:

    • single shared instance which formats dates for you
    • and that the object has some internal mutable state where it holds transient results (not necessarily a good design, but…).

    Would a shared instance help?

    Compared to creating a new instance every time? Yes. You would create far fewer transient objects. This could cost more than the calculation itself.

    In a heavily multithreaded context with many dates to transform, compared to having one instance per thread? No. You would need to lock, and the clients from all threads would be competing for the same resource. Your program would be faster if it were not multi-threaded. The good (general) solution in this case would be to create one formatter instance per thread to process all those dates, removing the need to lock the formatter while it processed each date.

    The high level question in the OP has no correct answer without context. You also need to understand your program and your problem well, and choose the right approach to the problem. The problem (or lack of a specific one) should not be an excuse to create a singleton.

    In general, I’d say that you should focus on good design first, but also be aware of your program’s execution problems and learn from them. Many developers who wait until there is a noticeable performance problem do not recognize (and consequently learn from) their past mistakes. So it helps to go in every once in a while and profile your app and learn how to improve those problems that arise, even if there is no “obvious performance problem”. Poorly constructed designs also have so many performance problems that the signal to noise ratio of a sample/profile will not be very useful — there will be many less than obvious issues, and many may be difficult to correct after the fact. By profiling and learning how to write optimized programs, you will be aware of performance considerations in advance, and avoid and recognize them next time you write a program. It will also take less time to recognize problems which arise in the future.

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

Sidebar

Related Questions

I'd like to remove all unchecked warnings from this general utility method (part of
Although I'm coding in Objective C, this is more of a general programming question.
I have a general coding style question for Objective C. When I have a
Yesterday I asked this general question about decimals and their internal precisions. Here is
This is a general question about MVC as a pattern, but in this case
This is a general question concerning technology decisions for a product development. My aim
This is a general question. And may not be specific to datagrids. How can
This is a general question about character encoding when using MD5 libraries in various
This is a general question. What are some techniques you employ to prevent the
This is a general question of sorts, but do you think that it's important

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.