load_stream loads the whole thing when used intuitively
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
檢查 lib/psych.rb 中 load_stream 實作附近的程式碼,並使用 issue 中的大型 YAML 範例比較有 block 和無 block 時的行為。完成的標準是,直觀的迭代能夠在不先將整個 stream 載入記憶體的情況下開始處理文件,同時現有的 block 用法仍然可用。
由索引模型根據 Issue 內容生成。
描述
Surprisingly, load_stream doesn't handle streams but loads all docs in an IO object at once, and only then iterates on the result. This results in much latency as well as huge swaths of memory being taken hostage when used intuitively.
Maybe this could return an Enumerator (that could be to_a) or do a lazy map (that could be forced).
Example "naive" code:
# tested with ruby 2.2.3
require 'yaml'
def rss
`ps -p #{Process.pid} -o rss`.split("\n").last.to_i
end
unless File.exist? 'test.yml'
File.open('test.yml', 'wb') do |f|
1_000_000.times do
f.write "---\n"
f.write format("foo: '%016x'\n", Random.rand(2**64))
end
end
end
s = YAML.load_stream File.open('test.yml')
puts 'loaded'
s.each.with_index do |_, i|
puts i if i % 100_000 == 0
end
puts "rss: #{rss} kB"
While load_stream does support a block arg, doing the following is cumbersome and non-discoverable:
s = Enumerator.new do |y|
YAML.load_stream(File.open('test.yml')) { |doc| y << doc }
end
- 主要語言
- Ruby
- 星號
- 596
- 分支
- 228
- 平均合併
- 24 分鐘
- 30 天內合併 PR
- 5
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ruby/psych 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆
-
Sexagesimal scalars are mis-scanned可能已有人在做 @ihamzatarar 於 13 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
Documentation
難度 1/5 1 小時以內 新手友好度 72/100
維護者通常 1 天內回覆
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 strings可能已有人在做 @Halvanhelv 於 83 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 55/100
維護者通常 1 天內回覆
-
Psych::Emitter#start_document: tag-directive handles and prefixes are aliased as raw `char *`, and the Strings die inside the loop可能已有人在做 @ninjapanzer 於 14 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 68/100
維護者通常 1 天內回覆
相似的 Issue
-
🐛 bug 👩💻 équipe CE
難度 2/5 1-3 小時 新手友好度 68/100
betagouv/conseillers-entreprises#4835 ·
維護者通常 1 天內回覆
-
backlog enhancement github_actions priority: low risk: low
難度 2/5 1-3 小時 新手友好度 77/100
davidteren/mutineer#646 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
metanorma/isodoc#965 · 1 則留言 ·
維護者通常 1 天內回覆
-
verified
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 4 天內回覆