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

Make accessing ChatClientConfig in the Database Layer safer #3566

Conversation

nuno-vieira
Copy link
Member

@nuno-vieira nuno-vieira commented Jan 17, 2025

🔗 Issue Links

Resolves https://linear.app/stream/issue/IOS-639/

🎯 Goal

Make accessing the ChatClientConfiginternally more thread safer.

🛠 Implementation

Initially, the idea was to pass ChatClientConfig around instead of accessing directly in the NSManagedObjectContext. The problem is that this would cause a massive amount of breaking changes. So the plans changed, and now the whole ChatClientConfig is stored in the NSManagedObjectContext.userInfo, but we make it thread-safe.

🧪 Manual Testing Notes

N/A

☑️ Contributor Checklist

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

@nuno-vieira nuno-vieira changed the title Make accessing the chat client config internally more thread safer Make accessing the chat client config internally thread safer Jan 17, 2025
@nuno-vieira nuno-vieira changed the title Make accessing the chat client config internally thread safer Make accessing the chat client config internally thread safe Jan 17, 2025
@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jan 17, 2025

SDK Size

title develop branch diff status
StreamChat 7.0 MB 7.0 MB 0 KB 🟢
StreamChatUI 4.77 MB 4.77 MB 0 KB 🟢

@nuno-vieira nuno-vieira force-pushed the fix/remove-chat-client-config-properties-from-coredata-contexts branch from 3cf4b87 to f9c67d2 Compare January 20, 2025 15:43
@nuno-vieira nuno-vieira marked this pull request as ready for review January 20, 2025 15:47
@nuno-vieira nuno-vieira requested a review from a team as a code owner January 20, 2025 15:47
@nuno-vieira nuno-vieira changed the title Make accessing the chat client config internally thread safe Make accessing ChatClientConfig in the Database Layer safer Jan 20, 2025
@Stream-SDK-Bot
Copy link
Collaborator

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 1.67 ms 83.3% 🔼 🟢
Duration 2.6 s 2.55 s 1.92% 🔼 🟢
Hitch time ratio 4 ms per s 0.66 ms per s 83.5% 🔼 🟢
Frame rate 75 fps 78.22 fps 4.29% 🔼 🟢
Number of hitches 1 0.2 80.0% 🔼 🟢

@nuno-vieira nuno-vieira force-pushed the fix/remove-chat-client-config-properties-from-coredata-contexts branch from 5ee6a44 to fa7b0f1 Compare January 20, 2025 16:35
@Stream-SDK-Bot
Copy link
Collaborator

Stream-SDK-Bot commented Jan 20, 2025

SDK Size

title develop branch diff status
StreamChat 7.0 MB 7.0 MB 0 KB 🟢
StreamChatUI 4.77 MB 4.77 MB 0 KB 🟢

@nuno-vieira nuno-vieira force-pushed the fix/remove-chat-client-config-properties-from-coredata-contexts branch from d65f904 to 5616a52 Compare January 20, 2025 16:46
Comment on lines +12 to +14
performAndWait {
config = userInfo[Self.chatClientConfigKey] as? ChatClientConfig
}
Copy link
Contributor

@laevandus laevandus Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does bring slight overhead (it is not huge, just tried sending 20 messages). Thinking if we want to do this since we fixed actual misuses already and this accessor is only used from asModel().
Screenshot 2025-01-21 at 09 59 07

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum I see, I'll do a couple more perf tests. But if there is a significant impact, maybe it is better we remove the performAndWait

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After running the benchmarking script on a real device, it looks like there is no significant impact:

image

For now, lets keep it this way to bulletproof, but if we find any issues with this in the future, we can remove the performAndWait 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's re-test this with this branch: #3564

For now we merge it as it

Copy link
Contributor

@laevandus laevandus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nuno-vieira nuno-vieira enabled auto-merge (squash) January 21, 2025 11:29
@nuno-vieira nuno-vieira merged commit 3756b9b into develop Jan 21, 2025
14 checks passed
@nuno-vieira nuno-vieira deleted the fix/remove-chat-client-config-properties-from-coredata-contexts branch January 21, 2025 11:30
@Stream-SDK-Bot Stream-SDK-Bot mentioned this pull request Jan 28, 2025
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.

3 participants