How to decrease CPU usage? [closed] - iphone

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I made a Swift app which runs very well on iPhone 6 and 6 plus, but when i test it on an iPhone 5 and below, there are some lags.
After analyzing, I saw a high CPU/memory consumption.
I want to know if there are some tips or best practices to reduce this usage?
I know it is very important to use different threads and return to idle when they are not used anymore, but I already do this.
The code which consumes the most resources creates a container (like the notification center) with some buttons on it and applies a blur effect below them.

When you say
After analyze, i saw a high CPU/memory consumption
was that using the time profiler instrument?
The Time Profiler will show you exactly what is consuming CPU resources, as well as your usage of the cores on the CPU, thread delays etc.
Time Profiling with Instruments

I've found this document from Apple to have good tips and tricks on improving performance.
Also make sure you are not doing resource intensive non-UI work on the main thread as this will cause lag on slower devices.

Ok i found where the problem was.
I use a library "FXBlur" to create the blur effect.
This library has a function which update the content of the container every second.
I just modified the code to remove this function, and my CPU usage is now oscillating between 0 and 3 % instead of the 37% that was before.
Thank you everybody for your help.

Related

HUAWEI mobile phone push delay too long sometimes, is there any solution? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Due to project reasons, there are certain requirements for push time, but now there are occasionally problems with this.Is there any way to reduce the time?
You can determine the cause of the delay according to the following methods, thereby reducing the delay:
1.Try to choose to push when the user's APP is online. If the user is offline, the message will be cached, and it will be discarded if it exceeds the time, causing a delay.
Do not push the server across regions.
Try to avoid the peak service period. When the pressure on Huawei servers is too much, there will be a delay.
Test the network problem and increase the network speed, otherwise it will cause delay.
It is recommended that developers test the test platform before pushing the message. If the test is not delayed, it is a problem of the developer server.
I think we need more information to really figure out the problem, but more generally there are a couple things you can consider first:
Do you use a lot of token-based/topic-based etc so that the system need more time to schedule?
Is your data storage location configured in the console suitable for your app's operating regions?
Do you send a lot of push messages in a short time?
If the above are all optimized and it's still slow you may need to contact their support to investigate if there's any problem

How big of a deal is a small memory leak? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
So I wrote an app in swift/xcode and now I'm at the finish line making sure everything is okay. Using Xcode's memory usage indicator, I noticed that my baseline memory usage increases by 200-300(kB) or about .25 (MB) when I play a level and then return to the main scene. So then I went to instruments and looked at persisting data. I'm thinking some SpriteNode has a runBlock creating a strong reference and found instances of textures with a high reference count, probably related to an explosion animation, and some sound sources weren't being released after the SKAction.playSoundFileNamed(...) was called. Anyways, I tried various fixes, haven't pinpointed whether its sound, explosion animation or something else, but it seems universal, happens after any level, which, along with Instruments, leads me to believe its one of the two (explosion animation or playsoundfile that creates a strong reference cycle). But then part of me feels like I'm chasing a ghost because I really haven't had any performance issues. I'm running in the 20-50 MB range so adding .2 MB per level really doesn't affect anything even if it does it a dozen times (the game is only 9 levels). Although as a perfectionist, it's driving me crazy. So being more practical:
Does apple care about a small memory leak? Does it test for that?
Whether they do or not, consider how this will affect your users. If someone loves your game enough to play it for several hours, will that end up impacting their experience? When is your application unloaded by the OS (i.e. how long will that memory usage persist)? It's obviously better not to leak memory, but "will Apple be unhappy with me" is a less important consideration than "will my users be unhappy with me."

How mongoDB handles memory managment? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
quote from http://blog.engineering.kiip.me/post/20988881092/a-year-with-mongodb
Poor Memory Management - MongoDB manages memory by memory mapping your
entire data set, leaving page cache management and faulting up to the
kernel. A more intelligent scheme would be able to do things like
fault in your indexes before use as well as handle faulting in of
cold/hot data more effectively. The result is that memory usage can’t
be effectively reasoned about, and performance is non-optimal.
I don't understand his point. Can someone elaborate on this?
As #cHao said it is a bit of a rant and the author doesn't really understand just how massively complex and intricate the OS' own memory management programs are.
This is why MongoDB does not have its own memory management, because to do so could cause a headache of problems and other nonsense. At the end of the day the OS has a really good memory management process (even Windows does) so why not use that instead of creating one that would require years, maybe even decades to get to the same level?
A more intelligent scheme would be able to do things like fault in your indexes before use
Not sure if MongoDB can read your mind...
I mean what if you have actually designed your system right and don't need ALL (or even those you do in their entirety) your indexes in RAM at the same time?
Doing such pre-emptive paging (not faulting) in of data sounds counter-intuitive to a good setup.
If you require data to be in RAM at certain times you can use touch() http://docs.mongodb.org/manual/reference/command/touch/ or you can run a scirpt of your common queries that you need in RAM.
The result is that memory usage can’t be effectively reasoned about, and performance is non-optimal.
Hmm, that person obviously never actually bothered to use the OS' own inbuilt tools to measure page faulting and memory accession of the mongod process in their testing.
That being said there is actually a tool in the latter version of MongoDB to help cauge memory usage: http://docs.mongodb.org/manual/reference/command/serverStatus/#server-status-workingset

How the number of connections of a usenet provider change something? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
At work, we are speaking about the interest to have 10 or 30 connections simultanly to a usenet provider.
Some guys said it change nothing because the 10 or 30 threads will take all the bandwidth available, so the download time will be the same.
Another guys said it change something because you can download more file at the same time.
Someone have a GOOD explanation to this problematic ? :)
Thanks ^^
The NNTP protocol has a lot of latency, so running multiple simultaneous connections can improve the speed of actions, particularly if there's a lot of back and forth with the server. (More recent versions of the protocol have support for streaming, but not many clients or servers know about this yet.) 10-30 sounds like overkill to me, though; usually you get the benefits of avoiding latency with 4-8 connections.
The best thing to do would be to test a variety of different numbers of connections for the exact thing you're trying to do and see which one is faster, though. It's going to depend on what types of actions you're taking.

State Pattern in iPhone applications (Memory Usage) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Does the state pattern in an iPhone application -- In my case, a relatively light-weight utility application -- use too much memory?
The state pattern, as I understand it, uses several classes; these classes represent different states. All of the different state objects are instantiated and stored in different pointer variables until the state is needed, at which point it is set to a curState object.
I figure that I could lazy load each state object to save some memory and loading time; I could then release the objects if my app receives a memory warning.
But what I wanted to know is does this pattern utilize too much memory for general usage in an iPhone OS application? Should iPhone developers stay away from this pattern? Is there a different pattern that is better suited to the iPhone OS?
Not worth worrying about. Unless your states are immensely complicated, or you have thousands and thousands of them, then any art or media files that are in your application will absolutely swamp them in size.
I mean in general - don't sweat the memory usage of your model objects. Objective-C objects are pretty lightweight, in terms of memory usage. If you've got a fairly typical model class, with say a half-dozen fields, each of which is a pointer to some other object, the total memory usage for each instance of that class is something like 32 bytes or so. If you put 1,000 of them into an array or some other data structure, that'd use about as much memory as a 128x128 bitmap.
You're much more likely to run into memory issues due to hanging on to graphics or sounds that you don't need to, than you ever will from the "working" parts of your application.