-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
FFTView poor performance as time passes #91
Comments
The bug is fully reproducible. Leaving the App open for some more minutes even leads to a crash. I'll have a quick look into the crash to gather more information. |
Code analysis:
|
@mahal appreciate your insight on this! To me it seems SwiftUI rendering is messing something up, as you showed the huge amount of views rendered one on top of another... I bet that's the key area to look in. In the mean time I just replace the rendering with Charts (iOS 16+) and it works perfect var body: some View {
GeometryReader { geometry in
ZStack {
Chart(Array(0 ..< barCount), id: \.self) { index in
makeBar(
index: index,
amplitude: amplitude(at: index),
viewHeight: geometry.size.height
)
}
.chartYScale(domain: 0 ... 0.9)
.chartXAxis(.hidden)
.chartYAxis(.hidden)
}
}
.onAppear {
fft.maxAmplitude = self.maxAmplitude
fft.minAmplitude = self.minAmplitude
callbacks.update = fft.update(buffer:)
callbacks.start = fft.start
callbacks.stop = fft.stop
}
.background(backgroundColor)
}
private func makeBar(index: Int, amplitude: Float, viewHeight: CGFloat) -> some ChartContent {
BarMark(
x: .value("Frequency", String(index)),
y: .value("Amplitude", amplitude)
)
.foregroundStyle(
linearGradient.in(CGRect(x: 0, y: 0, width: 0, height: viewHeight))
)
}
private func amplitude(at index: Int) -> Float {
if index < fft.amplitudes.count {
return fft.amplitudes[index]
} else {
return Constants.silence
}
} |
macOS Version(s) Used to Build
macOS 13 Ventura
Xcode Version(s)
Xcode 14
Description
I observe a decrease in frame rate for the FTTView as time passes. This can be observed in the cookbook example.
I attached a recording of the view performance after about 2 minutes of running. You can see the lag. Any ideas how to fix?
Crash Logs, Screenshots or Other Attachments (if applicable)
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-07-15.at.22.58.52.mp4
The text was updated successfully, but these errors were encountered: