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

画像探索が遅くなっている(Playwright関連コミットで) #1896

Closed
Nyoho opened this issue May 10, 2023 · 2 comments
Closed

画像探索が遅くなっている(Playwright関連コミットで) #1896

Nyoho opened this issue May 10, 2023 · 2 comments

Comments

@Nyoho
Copy link

Nyoho commented May 10, 2023

(masterを使ってみて気付きました) 5.7.0時点と比べてmasterのビルドがものすごく遅くなっていました。

プロファイラで調べたところ、このコミット a430616#diff-ad508b9b3fad48162f8630146009a8859aaa4ba68d0b1a1eacbdf29d97e4e74a で増えた

if downname == "#{target}#{ext}" || File.absolute_path(downname) == File.absolute_path("#{target}#{ext}")
の、次の部分がすごく遅いようでした。

File.absolute_path(downname) == File.absolute_path("#{target}#{ext}")

この探索アルゴリズムでは downname == "#{target}#{ext}" がほとんどの場合偽になるので、ほとんど後ろの File.absolute_path が評価されてしまって、システムを使い、すごく遅くなっているのではないかと思いました。

実験

今書いている本で計測しました。画像が160個ぐらいあります。
その1個1個に find_path メソッドが数百ミリ秒かかっていました。

  1. || File.absolute_path... ありでは rake epub に 106 秒
  2. || File.absolute_path... なしでは rake epub に 30 秒

懸念

このコミットがPlaywright Runnerを入れるコミットの一部であり、Playwrightにこの || File.absolute_path が必要なのかも知れません。しかしPlaywrightがよくわからない僕にはわかりません。
(自分のプロジェクトでは File.absolute_path が必要になることはなさそうなのですが)

変更案を考えてみました。

  1. Playwrightに || File.absolute_path が不必要なのでしたら外す
  2. 必要なのでしたら、まずFile.absolute_pathを使わない探索をして(高速)、それでもヒットしなかったらFile.absolute_pathを込めた探索をする実装に変更する
@kmuto
Copy link
Owner

kmuto commented May 10, 2023

あら、それは大変。ありがとうございます、確認します!

@Nyoho
Copy link
Author

Nyoho commented Jun 1, 2023

ありがとうございました!

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

2 participants