swift-server / guides

Guides for building, debugging and deploying Swift Server applications
258 stars 21 forks source link

swift high performance guide added #78

Open shilpeegupta14 opened 2 years ago

shilpeegupta14 commented 2 years ago

High Performance in Swift guide added

Motivation

Contributing to the repository.

Description:

Overview of the readme file: 1) Class vs Struct tradeoff and Copy-on-Write i)difference btw memory allocations ii)copy-on-write iii)benchmarking structs with classes iv)implementing structs backed by classes v) implementing structs backed by classes with copy on write

2) Concurrency and Locking i) Thread explosion ii) runtime contract iii) serial queue and concurrent queue iv) Synchronization offering:

  1. Mutual Exclusion
  2. Reentrancy and Prioritization
  3. Main Actor vii) Batching up code to improve time complexity viii) Lock Contention Pattern

References:

https://www.youtube.com/watch?v=iLDldae64xE https://www.youtube.com/watch?v=WCUj581Dpec https://developer.apple.com/videos/play/wwdc2021/10254/

Result:

Resolves: guide for writing high performance systems in swift

shilpeegupta14 commented 2 years ago

if there are any additions or deletions in my pr. Let me know!

tomerd commented 2 years ago

thanks @shilpeegupta14 will take a look shortly

tomerd commented 2 years ago

thanks or putting this together @shilpeegupta14

since this seems to be summarizing existing resources on the internet, how about we change the PR to be an "index for talks about performance in Swift"? this way we can add more links as we have more resources instead of repeating them. wdyt?

shilpeegupta14 commented 2 years ago

@tomerd thanks for taking out time to review this guide.

I am comfortable with the idea of changing the name of the pr and adding more resources. Some topics that I thought to write but wasn't sure if that comes in "high performance". Would like to know if I should add this or not: 1) copy on write on indices and on arrays, dictionaries. 2) operation queue vs gcd

topics/parts that I totally missed but will add: 1) how dispatch semaphore can handle race conditions. tradeoffs of dispatch semaphore and how they can lead to priority inversion and deadlocks. 2) how actors handle data races 3) async/await performance

If there are anymore resources to add, let me know. If I get any related one to performance in swift, I will add up on this.

shilpeegupta14 commented 2 years ago

@tomerd The pr shifted to https://github.com/swift-server/guides/pull/80 Sorry for the inconvenience