We are wanting to develop a Mobile App either a hybrid App or web app. Since Usability and performance are the main architectural drivers we are thinking Hybrid App is the best approach. But it is supposed to have these features. Because of development cost for each specific platform, Developing native app is out of question.

It will have an offline DB (i kind of wanting to go with a localForage which wraps IndexDB, Websql or will simply go with cordova-sqlite).DB Size will be around 15MB can grow upto 40MB in future.

It is supposed to do computations for an important operation. The operation involves reading data from database and running 10,000(or much more may be 40,000 ) loops with each loop doing some caluculation. As it is a hybrid App, we need to write this code in Javascript.

Now could you please tell me whether this computation (loops) will affect the battery usage in a big way (since there is cpu compuation) or is it Ok ? will the user response be good? On desktop this computation generally takes around 30-40seconds with cases where it can go beyond 1.5 minute (but we can restrict some functionalities)

we can decide to go with mobile web app with server doing compuation, but the responsiveness and performance will be not be good (may be). There is already a website (not a mobile web app or mobile website) available which does all the functionality

Dani AI

Generated

Brief summary and practical guidance for the scenario outlined by (offline DB in the tens of MB, a compute kernel that runs 10k–40k iterations and takes tens of seconds on desktop). is correct that moving heavy computation to a server removes most battery, thermal and UI-blocking concerns, but local execution is still viable when offline operation or privacy/latency requirements force it. The decision should be based on measurable tradeoffs rather than intuition.

When local execution is chosen, follow three core rules: 1) avoid DB round trips inside the hot loop, 2) keep heavy computation off the main thread, and 3) batch work so the OS can schedule other tasks. Practically, load the required rows once (single SELECT), convert numeric fields to typed arrays (Float32Array/Float64Array) and run the math against those in memory. Use prepared statements and transactions for any write-heavy operations. For keeping the UI responsive, use a Web Worker (or native plugin) for the tight loop and send occasional progress updates back to the UI.

Small, concrete patterns that work on Cordova/hybrid apps:

  • Pull all needed rows in one query, then post that data to a Web Worker.
  • In the worker split iterations into chunks and post progress every N iterations so the main thread can update a progress bar and allow cancellation.
  • If peak performance and energy efficiency are required, implement the kernel in WebAssembly or a native Cordova plugin; both usually beat pure JS for sustained numeric work.

Example chunking skeleton:

function processRows(rows, chunk=1000) {
  let i=0;
  function step() {
    const end = Math.min(i+chunk, rows.length);
    for (; i<end; i++) { /* numeric work on rows[i] */ }
    if (i<rows.length) setTimeout(step,0);
    else /* done */;
  }
  step();
}

Test on real target devices in release mode (devtools attached changes timing). Measure with performance.now, and use OS profilers (Android Studio / Instruments) to watch CPU, battery and temperature. If local runs would be many tens of seconds under realistic mobile conditions, prefer server-side computation or schedule local work only when the device is charging or on Wi-Fi, and always provide progress/cancel to preserve battery and user experience.

Recommended Answers

All 3 Replies

Simple advice, do not do these computations on device. Send request to server, let server deal with it and then push alert to device

Mr. Peter, could you please let me know why you think it should not be done on the device. Thanks for the reply

Resources constrains (cpu, ram, operating system), secondly current devices are more entertainment, quick search and not heavy duty computing devices

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.