Git Product home page Git Product logo

Comments (8)

rhcpfan avatar rhcpfan commented on June 10, 2024 2

I think I managed to solve the issue...

By looking at memory allocations, I've found that JHURepoDataService.parseTimeSerieses(data:, completion:) had the heaviest memory footprint. This was mainly because it took all 270 header values that represented time series dates and stored them as strings. Then, for every value in every time series (probably hundreds of thousands) called

let dateStrings = headers.dropFirst(4)
if let date = dateFormatter.date(from: dateString) {
    for confirmedTimeSeries in confirmed {
        for column in confirmedTimeSeries.values.indices {
            let dateString = dateStrings[dateStrings.startIndex + column]
            if let date = dateFormatter.date(from: dateString) {
                ...
            }
        }
    }
}

All the calls to .date(from: dateString) increase a lot the amount of memory used (and computation time).

The solution was to parse only the header values as dates and use them later in the process (this also comes with a great performance improvement):

let dateStrings = headers.dropFirst(4)
let dateValues = dateStrings.compactMap({ dateFormatter.date(from: $0) })
if let date = dateFormatter.date(from: dateString) {
    for confirmedTimeSeries in confirmed {
        for column in confirmedTimeSeries.values.indices {
            let dateString = dateStrings[dateStrings.startIndex + column]
            let date = dateValues[column]
            ...
        }
    }
}

Managed to reduce the memory used by a widget to ~15Mb from ~39Mb 👍

I still have to do a bit of more UI polishing and create a pull request (most likely tomorrow).

from coronatracker.

rhcpfan avatar rhcpfan commented on June 10, 2024 1

@mhdhejazi - just made a PR that only addresses the memory reduction stuff (#133)

from coronatracker.

mhdhejazi avatar mhdhejazi commented on June 10, 2024

Good idea. It'd be a great chance for learning too. I hope somebody jumps in and works on this.

from coronatracker.

gklka avatar gklka commented on June 10, 2024

I'd love to have this one too.

from coronatracker.

rhcpfan avatar rhcpfan commented on June 10, 2024

Hello there!

I've started working on some iOS 14 widgets for CoronaTracker, but I've hit a problem: the peak memory usage for a widget cannot exceed 30 Mb.

Currently, getting all the data from DataManager.shared.download takes the memory usage to ~39 Mb.
I've stripped out getting time series data from JHU (JHURepoDataService.shared.fetchTimeSerieses) and managed to reduce the memory footprint to ~ 31 Mb.

@mhdhejazi , is there a simple way to fetch some basic data (ex. just the dailyChange) for a single Region?

P.S: This is also the reason why the existing Today Extension is not working any more.
P.P.S: Here's a sneak peak on how they currently look (the simulator does not have this limitation) 😉

from coronatracker.

gklka avatar gklka commented on June 10, 2024

Looks great!

from coronatracker.

mhdhejazi avatar mhdhejazi commented on June 10, 2024

Wow, great work there and a nice catch. When I created the app the dataset was relatively small (both horizontally and vertically), so I didn't see the memory and performance issue. Thank you for fixing that.

Another idea to improve performance and memory usage could be by only parsing the data relevant to the current region. It could be challenging to do that without a big refactoring, but you can take a look at it.

from coronatracker.

FelikZ avatar FelikZ commented on June 10, 2024

it seems its solved in #134 ?

from coronatracker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.