Comments (8)
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.
@mhdhejazi - just made a PR that only addresses the memory reduction stuff (#133)
from coronatracker.
Good idea. It'd be a great chance for learning too. I hope somebody jumps in and works on this.
from coronatracker.
I'd love to have this one too.
from coronatracker.
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.
Looks great!
from coronatracker.
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.
it seems its solved in #134 ?
from coronatracker.
Related Issues (20)
- Scrolling issue on Mac HOT 4
- Lernen
- Provide IPA file for use with services like AltStore HOT 1
- performance issue on Mac Catalyst app HOT 13
- Compile iPA for sideloaders? HOT 1
- MacOS High Sierra with xcode 9.x HOT 2
- Bar title in "Daily New Cases" fails for USA HOT 1
- Loss of date HOT 4
- Diagram is clipping / not scaling correctly in logarithmic mode
- Corina
- Does not work for iOS 10.3. No such module WidgetKit
- Enable iOS widget on Big Sur
- iOS Widget not working
- Add the vaccination data HOT 1
- Zoom-in and zoom-out
- Project is crashing
- Corona tracker
- Repo
- AppStore download links HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coronatracker.