perf(websocket): switch WiFi to performance mode before connecting (#1985)
Some checks failed
Build Boards / Determine variants to build (push) Has been cancelled
Build Boards / Build ${{ matrix.full_name }} (push) Has been cancelled

* perf(websocket): switch WiFi to performance mode before connecting

Optimize WebSocket connection speed by switching WiFi to performance
mode before establishing the connection, instead of after.

This reduces network latency significantly:
- TCP connection: 1093ms → 88ms (92% faster)
- WebSocket handshake: 1035ms → 80ms (92% faster)
- Total network layer: 2128ms → 173ms (92% faster)

The issue was caused by WiFi power save mode (MAX_MODEM) which adds
significant latency to packet transmission.

* Adjust formatting
This commit is contained in:
liuzhe910422
2026-05-14 14:36:14 +08:00
committed by GitHub
parent 67bf599149
commit 417f52d759

View File

@ -716,6 +716,10 @@ void Application::ContinueOpenAudioChannel(ListeningMode mode) {
return;
}
// Switch to performance mode before connecting to reduce latency
auto& board = Board::GetInstance();
board.SetPowerSaveLevel(PowerSaveLevel::PERFORMANCE);
if (!protocol_->IsAudioChannelOpened()) {
if (!protocol_->OpenAudioChannel()) {
return;
@ -825,6 +829,10 @@ void Application::ContinueWakeWordInvoke(const std::string& wake_word) {
return;
}
// Switch to performance mode before connecting to reduce latency
auto& board = Board::GetInstance();
board.SetPowerSaveLevel(PowerSaveLevel::PERFORMANCE);
if (!protocol_->IsAudioChannelOpened()) {
if (!protocol_->OpenAudioChannel()) {
audio_service_.EnableWakeWordDetection(true);