Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory #708

Merged
merged 5 commits into from
Apr 15, 2019
Merged

Memory #708

merged 5 commits into from
Apr 15, 2019

Conversation

nikolai-b
Copy link
Contributor

Ref #707

This isn't ready but it shows the basic idea.

isolate renderLeaflet so the map isn't redrawn when the region$plot changes
Now region$plot is reactive these aren't needed
This means we store the processed files globally
@nikolai-b
Copy link
Contributor Author

I navigated to Hampshire on multiple different browser windows and recorded memory usage in R by pryr::mem_used()

Old code Sessions MB Newer code (before 78db7c8) Sessions MB Newest code Sessions MB
  1 166   1 168   1 185
  2 272   2 213   2 185
  3 378   3 259   3 186
  4 484   4 304   4 186
  5 590   5 351   5 187
  6 696   6 396   6 188

So now you can see multiple sessions adds hardly anything to the total MB of R objects!

I've added a cap so that objects are removed from the global list if there are more than 100 and they are removed last accessed == first removed. This is because I don't want that global list to get too large (loading all the rds files is ~ 15Gb).

This will need testing as I've also made to_plot a reactiveValue instead of it being a global object so lots of the observes have changed.

cc @Robinlovelace @usr110

@nikolai-b nikolai-b changed the title WIP: Memory Memory Apr 7, 2019
@Robinlovelace
Copy link
Member

Thanks @nikolai-b I just took a look at the code, looks clever. Look forward to testing this when back home next week. Have asked a few questions in the meantime. I suggest that if it passes informal tests by me and @usr110 we get others to test it on the test server with a before/after merge. Sound reasonable? I think this could make the app way more tolerant of many users so great work!

@Robinlovelace
Copy link
Member

I've tested on the latest version with the new tiles in all scenarios for commuting and schools and for multiple regions. Aside for making large regions load faster, I think, I can see no change. So merging. Great work @nikolai-b, many thanks!

filepath <- file.path(base_path, filename)

while (length(loaded_data) > 100) { # Rm objects from the list when too many (by time last accessed)
loaded_data[[names(loaded_data_accessed[loaded_data_accessed == min(unlist(loaded_data_accessed))])]] <<- NULL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does min(unlist(loaded_data_accessed)) here do?

rds <- readRDS(filepath)
if(filename == "rnet.Rds") {
if(!is.null(rds)){
rds$id <- rds$local_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry you've had to do that. We should have called it id initially I think but not worth changing now.

if(filename == "rq.Rds"){
# Merge in scenario data for quiet routes - don't want this in download but need for line sorting
rds@data <- cbind(
rds@data[!(names(rds) %in% names(str_lines))],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shows that shifting from sp to sf would be a massive operation. Not worth it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants