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
**Note**: OrderedCollection can cause memory spikes - when capacity is exceeded, it creates a new array 2x the size and copies all elements over, leading to O(n) performance degradation. In contrast, CTFIFOBuffer maintains constant O(1) performance with fixed memory usage.
I conducted comprehensive performance tests comparing three approaches i.e Arrays, Circular Buffers & Ordered Collections for maintaining the last 100 items. Here's what the data reveals:
155
155
156
-
### Test Run 1: Individual Performance
156
+
### Test Run: Average Performance
157
157
158
-

159
-
160
-
The first screenshot shows a single test run where I measured the execution time for each approach. You can see in the transcript:
### Results (average execution time over 100 test runs):
217
+
-**Array**: ~6 ms (variance: low)
218
+
-**Buffer**: ~14 ms (variance: low)
219
+
-**OrderedCollection**: ~31 ms (variance: high)
176
220
177
-
These averages confirm the trends observed in the individual test run - Circular Buffers provide a solid middle ground between raw speed and ease of use, while Ordered Collections lag behind due to their inherent inefficiencies.
221
+
### Why These Results Matter
178
222
179
-
### Test Run 3: Performance Benchmark
180
-

181
-
Using Pharo's bench method to measure sustained performance, measured in operations per 5 seconds. The results are:
223
+
**Array** is fastest but requires complex manual index management and wraparound logic - easy to introduce bugs.
182
224
183
-
-**Array**: ~756 iterations/5sec
184
-
-**Buffer**: ~351 iterations/5sec
185
-
-**OrderedCollection**: ~170 iterations/5sec
225
+
**Buffer** delivers excellent performance while eliminating all complexity. It's built on arrays internally, so it inherits array access costs plus method call overhead, making it ~2.3x slower than raw arrays. However, this trade-off is worth it because you get 43% of array speed with zero complexity.
186
226
187
-
### Why These Results Matter
227
+
**OrderedCollection** has multiple serious problems:
228
+
-**Slow removeFirst operations**: Shifts hundreds of elements every time
229
+
-**Memory spikes**: When internal capacity is exceeded, it creates a new array double the size and copies all elements, causing temporary memory usage spikes
188
230
189
-
-**Array (Manual Management)**
190
-
- Fastest performance
191
-
- Requires manual index logic and careful boundary checks
192
-
- Easy to introduce bugs & Hard to maintain
193
-
194
-
-**Circular Buffer**
195
-
- Nearly as fast as arrays
196
-
- Delivers 43% of Array speed while eliminating 100% of the complexity
197
-
- Automatically manages size
198
-
- Clean, safe, and maintainable for most use cases
199
-
200
-
-**OrderedCollection**
201
-
- Slowest performance
202
-
- Gets destroyed by `removeFirst` operations that shift hundreds of elements every time
203
-
- Not suitable for high-volume data management
231
+
This makes OrderedCollection unsuitable for high-volume streaming data or real-time applications.
0 commit comments