You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-3Lines changed: 27 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,13 +98,37 @@ For the coroutine server code, this is the kotlin version which is probably the
98
98
All the coroutine version were written the same. The coroutine code suspends while the event loop spins on memory. When the coroutine code resumes w/ the new value, it writes it.
99
99
100
100
101
-
### Suspend vs Resume
101
+
## Suspend vs Resume
102
+
103
+
The code flow for the coroutine code looks like this :
104
+
```mermaid
105
+
stateDiagram
106
+
state "Client Measures This" as time
107
+
state time {
108
+
SpinLoop --> Resume
109
+
Resume --> WriteValue
110
+
}
111
+
WriteValue --> Suspend
112
+
Suspend --> SpinLoop
113
+
```
102
114
103
-
The code flow for the coroutine code looks like this `SpinLoop->Resume->WriteValue->Suspend::Loop`Since the client is measuring the time it takes from `SpinLoop` to `WriteValue`, it most likely isn't measuring the time `Suspend` takes. There is no reason to think the time to `Resume` is the same as to `Suspend`.
115
+
Since the client is measuring the time it takes from `SpinLoop` to `WriteValue`, it most likely isn't measuring the time `Suspend` takes. There is no reason to think the time to `Resume` is the same as to `Suspend`.
104
116
105
117
If the event loop is dispatching the same event to multiple listeners, or had multiple events to dispatch, you bear the cost of both the suspend and resume for each event.
106
118
107
-
So I wrote two version of each coroutine. The version above is called the `Resume` version. The `Suspend` version code flow look like `SpinLoop->Suspend->WriteValue->Resume::Loop`. In the `Suspend` version the `SpinLoop` is in the coroutine code block, and the writing of the value is in the `eventLoop`.
119
+
So I wrote two version of each coroutine. The version above is called the `Resume` version. The `Suspend` version code flow looks like :
120
+
```mermaid
121
+
stateDiagram
122
+
state "Client Measures This" as time
123
+
state time {
124
+
SpinLoop --> Suspend
125
+
Suspend --> WriteValue
126
+
}
127
+
WriteValue --> Resume
128
+
Resume --> SpinLoop
129
+
```
130
+
131
+
In the `Suspend` version the `SpinLoop` is in the coroutine code block, and the writing of the value is in the `eventLoop`.
108
132
109
133
### Callbacks
110
134
The spin loop isn't a fair comparison to the coroutine code, so I added a callback version. I didn't write the reciprocal version of callback, like I did with the coroutine code. I'm just going to assume returning from a callback is cheap.
0 commit comments