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

画像ディレクトリのスキャン回数が多いためビルドが遅い #1916

Closed
Yuki-book opened this issue Aug 14, 2024 · 4 comments

Comments

@Yuki-book
Copy link

EPUBビルダの処理時間が多くなった原因は?

Issue #1915でEPUBビルダがおそいのは、WSL2の/mnt/でWindowsファイルをアクセスしているのが原因だと思っていました。

しかし、WSL2でls-l などでファイル操作してもそんなに処理時間がかかっていません。
IndexBuilderで約40秒もの間に何をしているのだろうと原因を追跡してみました。

ディレクトリスキャンが多い

ImageFinderのdir_entriesは、画像ディレクトリをスキャンしてリストを作成しています。

fig1

1回実行すればよいのですが、96回も実行していました。
Linuxでは軽い処理なのですが、WSL2の/mntでWindowsファイルをアクセスすると重い処理です。
この処理を96回も実行しているのがEPUBビルダを遅くしている原因です。

バックトレース

Rubyのcallerでバックトレースを取得しました。

• DEBUG   Create chapter_01.xhtml from content/chapter_01.re.
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/book/index.rb:141:in `new'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/book/index.rb:141:in `initialize'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/index_builder.rb:73:in `new'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/index_builder.rb:73:in `builder_init_file'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/index_builder.rb:51:in `bind'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/compiler.rb:282:in `do_compile'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/compiler.rb:55:in `compile'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/book/book_unit.rb:45:in `execute_indexer'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/book/book_unit.rb:54:in `generate_indexes'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/book/chapter.rb:60:in `generate_indexes'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/builder.rb:58:in `bind'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/compiler.rb:282:in `do_compile'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/compiler.rb:55:in `compile'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/converter.rb:19:in `convert'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/epubmaker.rb:407:in `build_chap'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/epubmaker.rb:312:in `block (2 levels) in build_body'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/epubmaker.rb:311:in `each'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/epubmaker.rb:311:in `block in build_body'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/epubmaker.rb:295:in `each'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/epubmaker.rb:295:in `build_body'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/epubmaker.rb:152:in `produce'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/epubmaker.rb:92:in `execute'
/var/lib/gems/3.2.0/gems/review-5.9.0/lib/review/epubmaker.rb:50:in `execute'
/var/lib/gems/3.2.0/gems/review-5.9.0/bin/review-epubmaker:15:in `<top (required)>'

解析結果

ImageFinderのinitializeを96回(12章×2回×4回)呼び出しています。

fig2

Rubyは素人なので間違っているかもしれませんが、明らかに重たい(ディスクアクセス)処理を必要以上に呼び出しています。
ぜひ、改善をよろしくお願いいたします。

@takahashim
Copy link
Collaborator

ご報告ありがとうございます。確かにここが重いのかもですね…。
ImageFinder#dir_entriesをcacheするようにしてみます。

@kmuto
Copy link
Owner

kmuto commented Aug 14, 2024

なるほど〜、詳細調査ありがとうございます!
takahashimさんにキャッシュ機構を作っていただいたので、これで1回読みだけになりそうです。

@Yuki-book
Copy link
Author

画像ディレクトリスキャンが1回になったので速くなりました。

Ver Time マシン
3.2.0 12.050秒 WSL Ubuntu 18.04
5.9.0 75.681秒 WSL2 Ubuntu 22.04
5.9.0対応版 8.748秒 WSL2 Ubuntu 22.04

Ver3.2.0の時より、高速になりました。

$ time review-master/bin/review-epubmaker config.yml
✔ SUCCESS built book03.epub

real    0m8.748s
user    0m5.278s
sys     0m0.274s

対応ありがとうございました。
これで、WSL2を使用しているユーザーも快適に使用することができます。

@kmuto
Copy link
Owner

kmuto commented Aug 15, 2024

解決とのことでcloseします〜 @takahashim ありがとうございました!

@kmuto kmuto closed this as completed Aug 15, 2024
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

No branches or pull requests

3 participants