Nested Futures Use More Memory Than They Should
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- r
調査の方向性
リポジトリのファイルやテストは指定されていません。まず、ネストされた future_lapply と future_map の例を使って sequential-plan ベンチマークを再現し、次に、ネストされた評価に関わる future と furrr のエントリポイントを追跡してください。ネストされた呼び出しが過剰にメモリを確保する理由を特定し、結果が同一のままメモリ使用量が急増しなくなったことを検証できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I've been running code with nested loops that keeps running into issues with memory usage and I have been trying to come up with a small example that potentially shows the problem. In the example I am just taking a random square matrix and creating a list of the columns. Obviously you wouldn't use a double loop to do this in R but it is hopefully a simple and clear example that shows when using purrr the double loop doesn't increase memory usage while with furrr and future.apply the memory usage explodes.
library(bench)
library(furrr)
library(future.apply)
library(purrr)
# purrr
single_loop <- function(x, n) {
map(1:n, ~ x[, .x])
}
# future.apply
single_loop_a <- function(x, n) {
future_lapply(1:n, FUN = function(i) x[, i])
}
# furrr
single_loop_f <- function(x, n) {
future_map(1:n, ~ x[, .x])
}
# purrr
inner_loop <- function(i, n, x = x) {
map_dbl(1:n, ~ x[.x, i])
}
outer_loop <- function(x, n) {
map(1:n, ~ inner_loop(.x, n, x = x))
}
# future.apply
inner_loop_a <- function(i, n, x = x) {
future_sapply(1:n, FUN = function(j) x[j, i])
}
outer_loop_a <- function(x, n) {
future_lapply(1:n, FUN = function(i) inner_loop_a(i, n, x))
}
# furrr
inner_loop_f <- function(i, n, x = x) {
future_map_dbl(1:n, ~ x[.x, i])
}
outer_loop_f <- function(x, n) {
future_map(1:n, ~ inner_loop_f(.x, n, x = x))
}
n <- 100
x <- matrix(rnorm(n * n), nrow = n)
identical(single_loop(x, n), single_loop_f(x, n))
identical(single_loop(x, n), single_loop_a(x, n))
identical(single_loop(x, n), outer_loop(x, n))
identical(single_loop(x, n), outer_loop_a(x, n))
identical(single_loop(x, n), outer_loop_f(x, n))
# All return TRUE
plan(sequential)
# With a single loop memory usage is similar
bench::mark(single_loop(x, n))$mem_alloc
# 127KB
bench::mark(single_loop_a(x, n))$mem_alloc
# 243KB
bench::mark(single_loop_f(x, n))$mem_alloc
# 340KB
# With a double loop memory usage remains similar for purrr, but explodes
# on the other two
bench::mark(outer_loop(x, n))$mem_alloc
# 83.6KB
bench::mark(outer_loop_a(x, n))$mem_alloc
# 11.8MB
bench::mark(outer_loop_f(x, n))$mem_alloc
# 21.1MB
# Try again with a larger matrix
n <- 5000
x <- matrix(rnorm(n * n), nrow = n)
bench::mark(single_loop(x, n))$mem_alloc
287MB
bench::mark(single_loop_a(x, n))$mem_alloc
287MB
bench::mark(single_loop_f(x, n))$mem_alloc
287MB
bench::mark(outer_loop(x, n))$mem_alloc
191MB
bench::mark(outer_loop_a(x, n))$mem_alloc
2.88GB
bench::mark(outer_loop_f(x, n))$mem_alloc
1.57GB
As you can see, using the double loop actually decreases memory usage for purrr, although it stays very similar, but causes memory usage to explode for furrr and future.apply. I ran this example on a 2023 MacBook, but the actual code that I am trying to fix has been running on a Linux cluster. I ran this example using furrr and future.apply because yesterday I logged a bug report about nested loops using future.callr and @HenrikBengtsson pointed out that it was only an issue with furrr. Please let me know if there is any additional information I can provide or help I can give in solving this issue and thanks for the wonderful collection of packages!
- 主要言語
- R
- スター
- 1k
- フォーク
- 93
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
futureverse/future のほかの issue
-
The first code example in the README does not work対応中かも @sean0407 が 5 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
futureverse/future#838 · コメント 1 件 · リアクション 1 件 ·
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
futureverse/future#833 ·
-
feature/resources RNG
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
futureverse/future#832 ·
-
RNG
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
futureverse/future#831 · コメント 1 件 ·
-
feature request
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
futureverse/future#822 · リアクション 1 件 ·
futureverse/future の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
AlexsLemonade/scpca-nf#1357 ·
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
REditorSupport/vscode-R#1883 ·
メンテナーはふだん 1 日以内に返信
-
Error out post processing step if there are multiple folders in /exec with the same index numberオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
bug documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信