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

音声デコード処理の改善 #16

Open
shun91 opened this issue Dec 10, 2021 · 3 comments
Open

音声デコード処理の改善 #16

shun91 opened this issue Dec 10, 2021 · 3 comments
Labels
impact - high 大きくパフォーマンスを改善できる可能性がある

Comments

@shun91
Copy link
Owner

shun91 commented Dec 10, 2021

ここが重い
https://github.com/shun91/web-speed-hackathon-2021/blob/main/client/src/components/foundation/SoundWaveSVG/SoundWaveSVG.jsx#L45-L49

@shun91
Copy link
Owner Author

shun91 commented Dec 10, 2021

image

image

@shun91
Copy link
Owner Author

shun91 commented Dec 11, 2021

calculate 関数のどこかが重いはず
https://github.com/shun91/web-speed-hackathon-2021/blob/main/client/src/components/foundation/SoundWaveSVG/SoundWaveSVG.jsx#L4-L31

↓のサウンドバー?の高さを算出するための処理っぽい
image

@shun91
Copy link
Owner Author

shun91 commented Dec 11, 2021

おもむろにperformance.now()で計測してみる

diff --git a/client/src/components/foundation/SoundWaveSVG/SoundWaveSVG.jsx b/client/src/components/foundation/SoundWaveSVG/SoundWaveSVG.jsx
index fa997ce..1f0d2a4 100644
--- a/client/src/components/foundation/SoundWaveSVG/SoundWaveSVG.jsx
+++ b/client/src/components/foundation/SoundWaveSVG/SoundWaveSVG.jsx
@@ -6,6 +6,7 @@ import React from 'react';
  * @returns {Promise<{ max: number, peaks: number[] }}
  */
 async function calculate(data) {
+  const start = performance.now();
   const audioCtx = new AudioContext();
 
   // 音声をデコードする
@@ -13,6 +14,8 @@ async function calculate(data) {
   const buffer = await new Promise((resolve, reject) => {
     audioCtx.decodeAudioData(data.slice(0), resolve, reject);
   });
+  console.log(performance.now() - start)
+
   // 左の音声データの絶対値を取る
   const leftData = _.map(buffer.getChannelData(0), Math.abs);
   // 右の音声データの絶対値を取る
@@ -27,6 +30,8 @@ async function calculate(data) {
   // chunk の平均の中から最大値を取る
   const max = _.max(peaks);
 
+  console.log(performance.now() - start)
+
   return { max, peaks };
 }

結果、全体的に重そう

1回目
image
2回目
image

パッと解決策は思いつかないので一旦後回し。。
(WebAudio周りの知見がなさすぎる。。)

@shun91 shun91 added the impact - high 大きくパフォーマンスを改善できる可能性がある label Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact - high 大きくパフォーマンスを改善できる可能性がある
Projects
None yet
Development

No branches or pull requests

1 participant