Skip to content

Commit bd52c73

Browse files
author
Oren (electricessence)
committed
Added ChannelObjectPool.
1 parent 6e5b210 commit bd52c73

6 files changed

Lines changed: 303 additions & 130 deletions

File tree

benchmarking/BenchmarkResult.csv

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
Batch,Pool Type," From Empty (In Parallel)"," To (In Parallel)",d Read/Write (In Parallel),y Pool (.TryTake()),L,
2-
Repeat 200000 for size 4,QueueObjectPool,00:00:00.8239435,00:00:00.7659438,00:00:00.7539503,00:00:00.0915139,00:00:02.4353515,
3-
Repeat 200000 for size 4,ConcurrentQueueObjectPool,00:00:00.8454852,00:00:00.8014094,00:00:00.7777634,00:00:00.0943980,00:00:02.5190560,
4-
Repeat 200000 for size 4,OptimisticArrayObjectPool,00:00:00.7514263,00:00:00.6102573,00:00:00.6096008,00:00:00.0250278,00:00:01.9963122,
5-
Repeat 80000 for size 10,QueueObjectPool,00:00:00.4331560,00:00:00.4100775,00:00:00.3880329,00:00:00.0806808,00:00:01.3119472,
6-
Repeat 80000 for size 10,ConcurrentQueueObjectPool,00:00:00.4329151,00:00:00.4102398,00:00:00.4300915,00:00:00.0956072,00:00:01.3688536,
7-
Repeat 80000 for size 10,OptimisticArrayObjectPool,00:00:00.4835332,00:00:00.3670787,00:00:00.3804679,00:00:00.0163851,00:00:01.2474649,
8-
Repeat 24000 for size 50,QueueObjectPool,00:00:00.2038919,00:00:00.4452561,00:00:00.2320728,00:00:00.1154980,00:00:00.9967188,
9-
Repeat 24000 for size 50,ConcurrentQueueObjectPool,00:00:00.1995862,00:00:00.2350584,00:00:00.2086107,00:00:00.1473526,00:00:00.7906079,
10-
Repeat 24000 for size 50,OptimisticArrayObjectPool,00:00:00.3295805,00:00:00.1578376,00:00:00.1925929,00:00:00.0135767,00:00:00.6935877,
11-
Repeat 16000 for size 100,QueueObjectPool,00:00:00.1852586,00:00:00.9325604,00:00:00.3417127,00:00:00.1384648,00:00:01.5979965,
12-
Repeat 16000 for size 100,ConcurrentQueueObjectPool,00:00:00.1971318,00:00:00.2221067,00:00:00.1930569,00:00:00.1769435,00:00:00.7892389,
13-
Repeat 16000 for size 100,OptimisticArrayObjectPool,00:00:00.4016048,00:00:00.1306689,00:00:00.1996246,00:00:00.0152044,00:00:00.7471027,
14-
Repeat 25600 for size 250,QueueObjectPool,00:00:00.4788340,00:00:02.5027144,00:00:02.0335266,00:00:00.4868144,00:00:05.5018894,
15-
Repeat 25600 for size 250,ConcurrentQueueObjectPool,00:00:00.4744855,00:00:00.6086463,00:00:00.5306288,00:00:00.6649206,00:00:02.2786812,
16-
Repeat 25600 for size 250,OptimisticArrayObjectPool,00:00:02.4850059,00:00:00.2867497,00:00:00.7016053,00:00:00.0496239,00:00:03.5229848,
17-
Repeat 9600 for size 1000,QueueObjectPool,00:00:00.4068512,00:00:02.3780043,00:00:01.7465435,00:00:00.6397193,00:00:05.1711183,
18-
Repeat 9600 for size 1000,ConcurrentQueueObjectPool,00:00:00.4151344,00:00:00.6236454,00:00:00.5478473,00:00:00.8236824,00:00:02.4103095,
19-
Repeat 9600 for size 1000,OptimisticArrayObjectPool,00:00:12.1866684,00:00:00.2235276,00:00:01.1323710,00:00:00.0608345,00:00:13.6034015,
20-
0:02.6057931,
21-
Repeat 9600 for size 1000,OptimisticArrayObjectPool,00:00:00.4008469,00:00:00.2035019,00:00:00.3460404,00:00:00.0013505,00:00:00.9517397,
22-
Repeat 9600 for size 1000,InterlockedArrayObjectPool,00:00:00.3981409,00:00:00.2025855,00:00:00.3609484,00:00:00.0012963,00:00:00.9629711,
23-
Repeat 6400 for size 2000,QueueObjectPool,00:00:00.5199373,00:00:02.5465317,00:00:02.4285615,00:00:00.8731311,00:00:06.3681616,
24-
Repeat 6400 for size 2000,ConcurrentQueueObjectPool,00:00:00.5197277,00:00:00.8558225,00:00:00.7322259,00:00:01.1357703,00:00:03.2435464,
25-
Repeat 6400 for size 2000,OptimisticArrayObjectPool,00:00:00.4943047,00:00:00.2297032,00:00:00.4033160,00:00:00.0010375,00:00:01.1283614,
26-
Repeat 6400 for size 2000,InterlockedArrayObjectPool,00:00:00.4761291,00:00:00.2311264,00:00:00.4388072,00:00:00.0009975,00:00:01.1470602,
2+
Repeat 200000 for size 4,QueueObjectPool,00:00:00.8414443,00:00:00.7491188,00:00:00.7633843,00:00:00.0939873,00:00:02.4479347,
3+
Repeat 200000 for size 4,ConcurrentQueueObjectPool,00:00:00.7907885,00:00:00.7635269,00:00:00.7739002,00:00:00.0956834,00:00:02.4238990,
4+
Repeat 200000 for size 4,OptimisticArrayObjectPool,00:00:00.8545861,00:00:00.7298007,00:00:00.7360451,00:00:00.0309048,00:00:02.3513367,
5+
Repeat 200000 for size 4,ChannelObjectPool,00:00:00.9057234,00:00:00.8273447,00:00:00.7409435,00:00:00.0901244,00:00:02.5641360,
6+
Repeat 80000 for size 10,QueueObjectPool,00:00:00.4912983,00:00:00.4533136,00:00:00.4291087,00:00:00.0878080,00:00:01.4615286,
7+
Repeat 80000 for size 10,ConcurrentQueueObjectPool,00:00:00.4694570,00:00:00.4624334,00:00:00.4517696,00:00:00.1010806,00:00:01.4847406,
8+
Repeat 80000 for size 10,OptimisticArrayObjectPool,00:00:00.5033997,00:00:00.3914612,00:00:00.4087611,00:00:00.0173492,00:00:01.3209712,
9+
Repeat 80000 for size 10,ChannelObjectPool,00:00:00.5184524,00:00:00.4868362,00:00:00.4049050,00:00:00.0772238,00:00:01.4874174,
10+
Repeat 24000 for size 50,QueueObjectPool,00:00:00.2166941,00:00:00.5193580,00:00:00.2609577,00:00:00.1199166,00:00:01.1169264,
11+
Repeat 24000 for size 50,ConcurrentQueueObjectPool,00:00:00.2071364,00:00:00.2237372,00:00:00.2196626,00:00:00.1443611,00:00:00.7948973,
12+
Repeat 24000 for size 50,OptimisticArrayObjectPool,00:00:00.3335099,00:00:00.1604842,00:00:00.1997833,00:00:00.0136419,00:00:00.7074193,
13+
Repeat 24000 for size 50,ChannelObjectPool,00:00:00.6503868,00:00:00.7734191,00:00:00.2313558,00:00:00.1015311,00:00:01.7566928,
14+
Repeat 16000 for size 100,QueueObjectPool,00:00:00.1955970,00:00:01.4124730,00:00:00.4856747,00:00:00.1556698,00:00:02.2494145,
15+
Repeat 16000 for size 100,ConcurrentQueueObjectPool,00:00:00.1850974,00:00:00.2225350,00:00:00.1948766,00:00:00.1859670,00:00:00.7884760,
16+
Repeat 16000 for size 100,OptimisticArrayObjectPool,00:00:00.4606833,00:00:00.1290964,00:00:00.2011276,00:00:00.0155033,00:00:00.8064106,
17+
Repeat 16000 for size 100,ChannelObjectPool,00:00:01.8300660,00:00:02.1177653,00:00:00.3798079,00:00:00.1307917,00:00:04.4584309,
18+
Repeat 25600 for size 250,QueueObjectPool,00:00:00.5207554,00:00:03.8471300,00:00:03.1776130,00:00:00.5699890,00:00:08.1154874,
19+
Repeat 25600 for size 250,ConcurrentQueueObjectPool,00:00:00.5144591,00:00:00.6581721,00:00:00.5638693,00:00:00.7343616,00:00:02.4708621,
20+
Repeat 25600 for size 250,OptimisticArrayObjectPool,00:00:03.0074967,00:00:00.3465589,00:00:00.7164117,00:00:00.0529356,00:00:04.1234029,
21+
Repeat 25600 for size 250,ChannelObjectPool,00:00:04.8289131,00:00:05.0525342,00:00:02.7992174,00:00:00.4744166,00:00:13.1550813,
22+
Repeat 9600 for size 1000,QueueObjectPool,00:00:00.4429800,00:00:02.5445855,00:00:02.5696949,00:00:00.7169192,00:00:06.2741796,
23+
Repeat 9600 for size 1000,ConcurrentQueueObjectPool,00:00:00.4447846,00:00:00.6793450,00:00:00.5848884,00:00:00.9255401,00:00:02.6345581,
24+
Repeat 9600 for size 1000,OptimisticArrayObjectPool,00:00:13.5246195,00:00:00.2524943,00:00:01.1490467,00:00:00.0721550,00:00:14.9983155,
25+
Repeat 9600 for size 1000,ChannelObjectPool,00:00:03.0021715,00:00:03.3152862,00:00:01.8869001,00:00:00.5896046,00:00:08.7939624,
26+
1264,00:00:00.4388072,00:00:00.0009975,00:00:01.1470602,
2727
Repeat 4800 for size 4000,QueueObjectPool,00:00:00.7134197,00:00:03.7582117,00:00:03.1855656,00:00:01.2950620,00:00:08.9522590,
2828
Repeat 4800 for size 4000,ConcurrentQueueObjectPool,00:00:00.7232603,00:00:01.2258140,00:00:01.0573101,00:00:01.6096397,00:00:04.6160241,
2929
Repeat 4800 for size 4000,OptimisticArrayObjectPool,00:00:00.6968814,00:00:00.3086700,00:00:00.5845562,00:00:00.0007690,00:00:01.5908766,

benchmarking/BenchmarkResult.txt

Lines changed: 132 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,149 +2,191 @@ Repeat 200000 for size 4
22
------------------------------------
33

44
QueueObjectPool.........................................
5-
00:00:00.8239435 Take From Empty (In Parallel)
6-
00:00:00.7659438 Give To (In Parallel)
7-
00:00:00.7539503 Mixed Read/Write (In Parallel)
8-
00:00:00.0915139 Empty Pool (.TryTake())
9-
00:00:02.4353515 TOTAL
5+
00:00:00.8414443 Take From Empty (In Parallel)
6+
00:00:00.7491188 Give To (In Parallel)
7+
00:00:00.7633843 Mixed Read/Write (In Parallel)
8+
00:00:00.0939873 Empty Pool (.TryTake())
9+
00:00:02.4479347 TOTAL
1010

1111
ConcurrentQueueObjectPool...............................
12-
00:00:00.8454852 Take From Empty (In Parallel)
13-
00:00:00.8014094 Give To (In Parallel)
14-
00:00:00.7777634 Mixed Read/Write (In Parallel)
15-
00:00:00.0943980 Empty Pool (.TryTake())
16-
00:00:02.5190560 TOTAL
12+
00:00:00.7907885 Take From Empty (In Parallel)
13+
00:00:00.7635269 Give To (In Parallel)
14+
00:00:00.7739002 Mixed Read/Write (In Parallel)
15+
00:00:00.0956834 Empty Pool (.TryTake())
16+
00:00:02.4238990 TOTAL
1717

1818
OptimisticArrayObjectPool...............................
19-
00:00:00.7514263 Take From Empty (In Parallel)
20-
00:00:00.6102573 Give To (In Parallel)
21-
00:00:00.6096008 Mixed Read/Write (In Parallel)
22-
00:00:00.0250278 Empty Pool (.TryTake())
23-
00:00:01.9963122 TOTAL
19+
00:00:00.8545861 Take From Empty (In Parallel)
20+
00:00:00.7298007 Give To (In Parallel)
21+
00:00:00.7360451 Mixed Read/Write (In Parallel)
22+
00:00:00.0309048 Empty Pool (.TryTake())
23+
00:00:02.3513367 TOTAL
24+
25+
ChannelObjectPool.......................................
26+
00:00:00.9057234 Take From Empty (In Parallel)
27+
00:00:00.8273447 Give To (In Parallel)
28+
00:00:00.7409435 Mixed Read/Write (In Parallel)
29+
00:00:00.0901244 Empty Pool (.TryTake())
30+
00:00:02.5641360 TOTAL
2431

2532

2633
Repeat 80000 for size 10
2734
------------------------------------
2835

2936
QueueObjectPool.........................................
30-
00:00:00.4331560 Take From Empty (In Parallel)
31-
00:00:00.4100775 Give To (In Parallel)
32-
00:00:00.3880329 Mixed Read/Write (In Parallel)
33-
00:00:00.0806808 Empty Pool (.TryTake())
34-
00:00:01.3119472 TOTAL
37+
00:00:00.4912983 Take From Empty (In Parallel)
38+
00:00:00.4533136 Give To (In Parallel)
39+
00:00:00.4291087 Mixed Read/Write (In Parallel)
40+
00:00:00.0878080 Empty Pool (.TryTake())
41+
00:00:01.4615286 TOTAL
3542

3643
ConcurrentQueueObjectPool...............................
37-
00:00:00.4329151 Take From Empty (In Parallel)
38-
00:00:00.4102398 Give To (In Parallel)
39-
00:00:00.4300915 Mixed Read/Write (In Parallel)
40-
00:00:00.0956072 Empty Pool (.TryTake())
41-
00:00:01.3688536 TOTAL
44+
00:00:00.4694570 Take From Empty (In Parallel)
45+
00:00:00.4624334 Give To (In Parallel)
46+
00:00:00.4517696 Mixed Read/Write (In Parallel)
47+
00:00:00.1010806 Empty Pool (.TryTake())
48+
00:00:01.4847406 TOTAL
4249

4350
OptimisticArrayObjectPool...............................
44-
00:00:00.4835332 Take From Empty (In Parallel)
45-
00:00:00.3670787 Give To (In Parallel)
46-
00:00:00.3804679 Mixed Read/Write (In Parallel)
47-
00:00:00.0163851 Empty Pool (.TryTake())
48-
00:00:01.2474649 TOTAL
51+
00:00:00.5033997 Take From Empty (In Parallel)
52+
00:00:00.3914612 Give To (In Parallel)
53+
00:00:00.4087611 Mixed Read/Write (In Parallel)
54+
00:00:00.0173492 Empty Pool (.TryTake())
55+
00:00:01.3209712 TOTAL
56+
57+
ChannelObjectPool.......................................
58+
00:00:00.5184524 Take From Empty (In Parallel)
59+
00:00:00.4868362 Give To (In Parallel)
60+
00:00:00.4049050 Mixed Read/Write (In Parallel)
61+
00:00:00.0772238 Empty Pool (.TryTake())
62+
00:00:01.4874174 TOTAL
4963

5064

5165
Repeat 24000 for size 50
5266
------------------------------------
5367

5468
QueueObjectPool.........................................
55-
00:00:00.2038919 Take From Empty (In Parallel)
56-
00:00:00.4452561 Give To (In Parallel)
57-
00:00:00.2320728 Mixed Read/Write (In Parallel)
58-
00:00:00.1154980 Empty Pool (.TryTake())
59-
00:00:00.9967188 TOTAL
69+
00:00:00.2166941 Take From Empty (In Parallel)
70+
00:00:00.5193580 Give To (In Parallel)
71+
00:00:00.2609577 Mixed Read/Write (In Parallel)
72+
00:00:00.1199166 Empty Pool (.TryTake())
73+
00:00:01.1169264 TOTAL
6074

6175
ConcurrentQueueObjectPool...............................
62-
00:00:00.1995862 Take From Empty (In Parallel)
63-
00:00:00.2350584 Give To (In Parallel)
64-
00:00:00.2086107 Mixed Read/Write (In Parallel)
65-
00:00:00.1473526 Empty Pool (.TryTake())
66-
00:00:00.7906079 TOTAL
76+
00:00:00.2071364 Take From Empty (In Parallel)
77+
00:00:00.2237372 Give To (In Parallel)
78+
00:00:00.2196626 Mixed Read/Write (In Parallel)
79+
00:00:00.1443611 Empty Pool (.TryTake())
80+
00:00:00.7948973 TOTAL
6781

6882
OptimisticArrayObjectPool...............................
69-
00:00:00.3295805 Take From Empty (In Parallel)
70-
00:00:00.1578376 Give To (In Parallel)
71-
00:00:00.1925929 Mixed Read/Write (In Parallel)
72-
00:00:00.0135767 Empty Pool (.TryTake())
73-
00:00:00.6935877 TOTAL
83+
00:00:00.3335099 Take From Empty (In Parallel)
84+
00:00:00.1604842 Give To (In Parallel)
85+
00:00:00.1997833 Mixed Read/Write (In Parallel)
86+
00:00:00.0136419 Empty Pool (.TryTake())
87+
00:00:00.7074193 TOTAL
88+
89+
ChannelObjectPool.......................................
90+
00:00:00.6503868 Take From Empty (In Parallel)
91+
00:00:00.7734191 Give To (In Parallel)
92+
00:00:00.2313558 Mixed Read/Write (In Parallel)
93+
00:00:00.1015311 Empty Pool (.TryTake())
94+
00:00:01.7566928 TOTAL
7495

7596

7697
Repeat 16000 for size 100
7798
------------------------------------
7899

79100
QueueObjectPool.........................................
80-
00:00:00.1852586 Take From Empty (In Parallel)
81-
00:00:00.9325604 Give To (In Parallel)
82-
00:00:00.3417127 Mixed Read/Write (In Parallel)
83-
00:00:00.1384648 Empty Pool (.TryTake())
84-
00:00:01.5979965 TOTAL
101+
00:00:00.1955970 Take From Empty (In Parallel)
102+
00:00:01.4124730 Give To (In Parallel)
103+
00:00:00.4856747 Mixed Read/Write (In Parallel)
104+
00:00:00.1556698 Empty Pool (.TryTake())
105+
00:00:02.2494145 TOTAL
85106

86107
ConcurrentQueueObjectPool...............................
87-
00:00:00.1971318 Take From Empty (In Parallel)
88-
00:00:00.2221067 Give To (In Parallel)
89-
00:00:00.1930569 Mixed Read/Write (In Parallel)
90-
00:00:00.1769435 Empty Pool (.TryTake())
91-
00:00:00.7892389 TOTAL
108+
00:00:00.1850974 Take From Empty (In Parallel)
109+
00:00:00.2225350 Give To (In Parallel)
110+
00:00:00.1948766 Mixed Read/Write (In Parallel)
111+
00:00:00.1859670 Empty Pool (.TryTake())
112+
00:00:00.7884760 TOTAL
92113

93114
OptimisticArrayObjectPool...............................
94-
00:00:00.4016048 Take From Empty (In Parallel)
95-
00:00:00.1306689 Give To (In Parallel)
96-
00:00:00.1996246 Mixed Read/Write (In Parallel)
97-
00:00:00.0152044 Empty Pool (.TryTake())
98-
00:00:00.7471027 TOTAL
115+
00:00:00.4606833 Take From Empty (In Parallel)
116+
00:00:00.1290964 Give To (In Parallel)
117+
00:00:00.2011276 Mixed Read/Write (In Parallel)
118+
00:00:00.0155033 Empty Pool (.TryTake())
119+
00:00:00.8064106 TOTAL
120+
121+
ChannelObjectPool.......................................
122+
00:00:01.8300660 Take From Empty (In Parallel)
123+
00:00:02.1177653 Give To (In Parallel)
124+
00:00:00.3798079 Mixed Read/Write (In Parallel)
125+
00:00:00.1307917 Empty Pool (.TryTake())
126+
00:00:04.4584309 TOTAL
99127

100128

101129
Repeat 25600 for size 250
102130
------------------------------------
103131

104132
QueueObjectPool.........................................
105-
00:00:00.4788340 Take From Empty (In Parallel)
106-
00:00:02.5027144 Give To (In Parallel)
107-
00:00:02.0335266 Mixed Read/Write (In Parallel)
108-
00:00:00.4868144 Empty Pool (.TryTake())
109-
00:00:05.5018894 TOTAL
133+
00:00:00.5207554 Take From Empty (In Parallel)
134+
00:00:03.8471300 Give To (In Parallel)
135+
00:00:03.1776130 Mixed Read/Write (In Parallel)
136+
00:00:00.5699890 Empty Pool (.TryTake())
137+
00:00:08.1154874 TOTAL
110138

111139
ConcurrentQueueObjectPool...............................
112-
00:00:00.4744855 Take From Empty (In Parallel)
113-
00:00:00.6086463 Give To (In Parallel)
114-
00:00:00.5306288 Mixed Read/Write (In Parallel)
115-
00:00:00.6649206 Empty Pool (.TryTake())
116-
00:00:02.2786812 TOTAL
140+
00:00:00.5144591 Take From Empty (In Parallel)
141+
00:00:00.6581721 Give To (In Parallel)
142+
00:00:00.5638693 Mixed Read/Write (In Parallel)
143+
00:00:00.7343616 Empty Pool (.TryTake())
144+
00:00:02.4708621 TOTAL
117145

118146
OptimisticArrayObjectPool...............................
119-
00:00:02.4850059 Take From Empty (In Parallel)
120-
00:00:00.2867497 Give To (In Parallel)
121-
00:00:00.7016053 Mixed Read/Write (In Parallel)
122-
00:00:00.0496239 Empty Pool (.TryTake())
123-
00:00:03.5229848 TOTAL
147+
00:00:03.0074967 Take From Empty (In Parallel)
148+
00:00:00.3465589 Give To (In Parallel)
149+
00:00:00.7164117 Mixed Read/Write (In Parallel)
150+
00:00:00.0529356 Empty Pool (.TryTake())
151+
00:00:04.1234029 TOTAL
152+
153+
ChannelObjectPool.......................................
154+
00:00:04.8289131 Take From Empty (In Parallel)
155+
00:00:05.0525342 Give To (In Parallel)
156+
00:00:02.7992174 Mixed Read/Write (In Parallel)
157+
00:00:00.4744166 Empty Pool (.TryTake())
158+
00:00:13.1550813 TOTAL
124159

125160

126161
Repeat 9600 for size 1000
127162
------------------------------------
128163

129164
QueueObjectPool.........................................
130-
00:00:00.4068512 Take From Empty (In Parallel)
131-
00:00:02.3780043 Give To (In Parallel)
132-
00:00:01.7465435 Mixed Read/Write (In Parallel)
133-
00:00:00.6397193 Empty Pool (.TryTake())
134-
00:00:05.1711183 TOTAL
165+
00:00:00.4429800 Take From Empty (In Parallel)
166+
00:00:02.5445855 Give To (In Parallel)
167+
00:00:02.5696949 Mixed Read/Write (In Parallel)
168+
00:00:00.7169192 Empty Pool (.TryTake())
169+
00:00:06.2741796 TOTAL
135170

136171
ConcurrentQueueObjectPool...............................
137-
00:00:00.4151344 Take From Empty (In Parallel)
138-
00:00:00.6236454 Give To (In Parallel)
139-
00:00:00.5478473 Mixed Read/Write (In Parallel)
140-
00:00:00.8236824 Empty Pool (.TryTake())
141-
00:00:02.4103095 TOTAL
172+
00:00:00.4447846 Take From Empty (In Parallel)
173+
00:00:00.6793450 Give To (In Parallel)
174+
00:00:00.5848884 Mixed Read/Write (In Parallel)
175+
00:00:00.9255401 Empty Pool (.TryTake())
176+
00:00:02.6345581 TOTAL
142177

143178
OptimisticArrayObjectPool...............................
144-
00:00:12.1866684 Take From Empty (In Parallel)
145-
00:00:00.2235276 Give To (In Parallel)
146-
00:00:01.1323710 Mixed Read/Write (In Parallel)
147-
00:00:00.0608345 Empty Pool (.TryTake())
148-
00:00:13.6034015 TOTAL
179+
00:00:13.5246195 Take From Empty (In Parallel)
180+
00:00:00.2524943 Give To (In Parallel)
181+
00:00:01.1490467 Mixed Read/Write (In Parallel)
182+
00:00:00.0721550 Empty Pool (.TryTake())
183+
00:00:14.9983155 TOTAL
184+
185+
ChannelObjectPool.......................................
186+
00:00:03.0021715 Take From Empty (In Parallel)
187+
00:00:03.3152862 Give To (In Parallel)
188+
00:00:01.8869001 Mixed Read/Write (In Parallel)
189+
00:00:00.5896046 Empty Pool (.TryTake())
190+
00:00:08.7939624 TOTAL
149191

150192

benchmarking/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ static void Main(string[] args)
3131
count => () => ConcurrentQueueObjectPool.Create<object>((int)count * 2));
3232
report.AddBenchmark("OptimisticArrayObjectPool",
3333
count => () => OptimisticArrayObjectPool.Create<object>((int)count * 2));
34+
report.AddBenchmark("ChannelObjectPool",
35+
count => () => ChannelObjectPool.Create<object>((int)count * 2));
3436
report.Pretest(200, 200); // Run once through first to scramble/warm-up initial conditions.
3537

3638
Console.SetCursorPosition(0, Console.CursorTop);

source/Dataflow/BufferBlockObjectPool.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
43
using System.Threading;
54
using System.Threading.Tasks;
@@ -86,7 +85,7 @@ protected override async Task<T> TakeAsyncInternal()
8685

8786
// This is a rare edge case where there's no fault but did not complete. Effectively erroneous.
8887
Debug.Fail("Somehow the generate task did not complete and had no fault.");
89-
return base.Take();
88+
return Take();
9089
}
9190
}
9291
}
@@ -95,19 +94,7 @@ protected override async Task<T> TakeAsyncInternal()
9594
return taken.Result;
9695
}
9796

98-
return base.Take(); // Pool is closed/completed. Just do this here without queueing.
99-
}
100-
101-
public override sealed T Take()
102-
{
103-
// See if there's one available already.
104-
if (TryTake(out T firstTry))
105-
return firstTry;
106-
107-
if (_pool == null)
108-
return Factory();
109-
110-
return TakeAsync().Result;
97+
return Take(); // Pool is closed/completed. Just do this here without queueing.
11198
}
11299

113100
protected override void OnDispose(bool calledExplicitly)

0 commit comments

Comments
 (0)