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

Fix SystemSpeechSynthesizer related main thread hang on NavigationViewController creation #4617

Merged
merged 2 commits into from
Mar 27, 2024

Conversation

azarovalex
Copy link
Contributor

@azarovalex azarovalex commented Mar 26, 2024

Description

There is an old iOS issue with AVSpeechSynthesizer: each access to it triggers XPC communication, which hangs the thread on which the object is accessed: https://stackoverflow.com/questions/53912072/avspeechsynthesizer-freezes-ios-app-for-a-few-seconds.

Xcode 15.3 now highlights this issue with console warnings like:

Warning example
Thread Performance Checker: Thread running at User-interactive quality-of-service class waiting on a lower QoS thread running at Default quality-of-service class. Investigate ways to avoid priority inversions
PID: 13043, TID: 7057855
Backtrace
=================================================================
3   Foundation                          0x000000018888e37c 5623831D-5719-33A9-9691-759F47D714D1 + 7627644
4   Foundation                          0x00000001882426e4 5623831D-5719-33A9-9691-759F47D714D1 + 1025764
5   Foundation                          0x000000018826974c 5623831D-5719-33A9-9691-759F47D714D1 + 1185612
6   TextToSpeech                        0x00000001a9c78878 TTSSpeechTransformTextWithLanguageAndVoiceIdentifier + 5132
7   TextToSpeech                        0x00000001a9c7df20 AXAVSpeechSynthesisVoiceFromTTSSpeechVoice + 13132
8   TextToSpeech                        0x00000001a9c76020 _TTSIdentifierForVoiceInformation + 17508
9   MyAwesomeApp                  0x00000001051f78f4 $s16MapboxNavigation23SystemSpeechSynthesizerC10isSpeakingSbvg + 44
10  MyAwesomeApp                  0x00000001051f728c $s16MapboxNavigation23SystemSpeechSynthesizerC5mutedSbvW + 60
11  MyAwesomeApp                  0x00000001051f73a8 $s16MapboxNavigation23SystemSpeechSynthesizerC5mutedSbvs + 120
12  MyAwesomeApp                  0x00000001051f9ef4 $s16MapboxNavigation23SystemSpeechSynthesizerCAA0D12SynthesizingA2aDP5mutedSbvsTW + 40
13  MyAwesomeApp                  0x0000000105088934 $s16MapboxNavigation28MultiplexedSpeechSynthesizerC9applyMute33_C78A32105F77292EE97E3E9C94F947E2LLyyFyAA0D12Synthesizing_pXEfU_ + 128

While we can't fix this problem in Apple system library, we only access AVSpeechSynthesizer when it's really necessary. Right now NavigationViewController.viewDidLoad leads to a mutation of SystemSpeechSynthesizer.muted property, which in turn accesses AVSpeechSynthesizer, even though it's not really used.

Implementation

When mutating SystemSpeechSynthesizer.muted, we only try to interrupt it when muted == true, skipping isSpeaking getter.

@azarovalex azarovalex self-assigned this Mar 26, 2024
@azarovalex azarovalex requested a review from a team as a code owner March 26, 2024 18:31
Copy link

codecov bot commented Mar 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.54%. Comparing base (dc90edc) to head (fcbd0d1).

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4617   +/-   ##
=======================================
  Coverage   60.54%   60.54%           
=======================================
  Files         189      189           
  Lines       21297    21297           
=======================================
  Hits        12894    12894           
  Misses       8403     8403           
Files Coverage Δ
...ces/MapboxNavigation/SystemSpeechSynthesizer.swift 46.04% <100.00%> (ø)

@azarovalex azarovalex merged commit 38b45ba into main Mar 27, 2024
21 checks passed
@azarovalex azarovalex deleted the azarovalex/fix-avspeechsynthesizer-hang branch March 27, 2024 12:55
@azarovalex azarovalex restored the azarovalex/fix-avspeechsynthesizer-hang branch March 27, 2024 13:16
azarovalex added a commit that referenced this pull request Apr 15, 2024
* Use camera options to calculate zoom for overview camera (#4593)

* Use camera options to calculate zoom for overview camera

* Create dependabot.yml

Enable Dependabot version updates

* Bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump github/codeql-action from 2 to 3

Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@v2...v3)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fixed the possible situation when the upcoming route leg is rendered above the active route leg (#4589)

* Add the ability to set locale for top and bottom banner views (#4595)

* Implement configurable waypoints in CarPlayDelegate

* Update Tests/MapboxNavigationTests/CarPlayUtils.swift

Co-authored-by: Nastassia Makaranka <nastassia.makaranka@mapbox.com>

* Update CHANGELOG.md

Co-authored-by: Nastassia Makaranka <nastassia.makaranka@mapbox.com>

* Update dependencies (#4614)

* vk/dependencies-update: bumped Directions to 2.12.0, Maps to 10.16.5. Now compatible with Turf 2.7.0.

* vk/dependencies-update: CHANGELOG updated

* vk/dependencies-update: bumped NN to v202; update cocoapods in gemfile to 1.14

* vk/dependencies-update: unit tests fix

* Sync Package.resolved with last resolved dependencies

* Update CHANGELOG.md

* Sync CocoaPodsTest

---------

Co-authored-by: Udumft <viktor.kononov@mapbox.com>

* Fix SystemSpeechSynthesizer related main thread hang on NavigationViewController creation (#4617)

* Don't check if AVSpeechSynthesizer.isSpeaking when unmuting it

* add changelog entry

* Improve error handing in case of invalid route responses (#4618)

* Improve error handing in case of invalid route responses

* Fix the order in which delegate is notified about failed reroute attempt

* Fix for old Swift compiler versions

* Fixed project structure in Carthage integration

* Added changelog entry

* Fix Examples signing when building on a real device (#4619)

* Fix Examples signing when building on a real device

* Replace build phases with the new script in 3 test targets

* Grant exec permissions to the script

* Fix carplay background maneuver card

* Fix method annotation and desctiption

* Update changelog

* Fix compile errors

* Update breaking changes list

* Update changelog

* Update spelling

* Fix spelling

* Update CHANGELOG.md

* Update NN and Maps (#4628)

* Update NN and Maps

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Nastassia Makaranka <nastassia.makaranka@mapbox.com>
Co-authored-by: Thibaud Lopez Schneider <ThibaudLopez@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max <max.chizhavko@mapbox.com>
Co-authored-by: Max <70526783+chizhavko@users.noreply.github.com>
Co-authored-by: Udumft <viktor.kononov@mapbox.com>
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

Successfully merging this pull request may close these issues.

2 participants