Commit 2903373
committed
use
Currently as noted in the comment of `putRunner`, there's no attempt
being made to limit the size of the runner pooling - this can result in
the pool containing a lot of runners that were once created in a spur
but will likely not be used anymore. Instead of trying to do gc within
this code, move the pooling to `sync.Pool` which will deallocated objects
in idle and therefore keep the size of the pool as small as possible. For proper
usage of `sync.Pool` there must be a hard limit on the size of `runtrack`,
`runstrack`, `runcrawl` in the case they are too big they will not be
cached, the `initMatch` function has been adjusted to make sure if one
of three slices weren't cached they will be allocated again.
The pool is global and not per-regexp because sync.Pool has a noCopy
struct which conflicts with the the UnmarshalText function of `Regexp`.
This should have the added benefit that if you're executing many
different regexps they will benefit from each other allocated runners.
The motivation for this change is that I'm seeing a lot of memory (~300MiB) being
hold by these runners until the Go program is restarted which feels like
an unoptimal usage of memory, with this change after a spur of these
runners have been created in a small amount of time they are gracefully
deallocated over time and no longer hold memory indefinitely.sync.Pool for runner pooling1 parent 5f3687a commit 2903373
2 files changed
+48
-57
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 47 | | |
53 | 48 | | |
54 | 49 | | |
| |||
76 | 71 | | |
77 | 72 | | |
78 | 73 | | |
79 | | - | |
80 | 74 | | |
81 | 75 | | |
82 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
1356 | 1357 | | |
1357 | 1358 | | |
1358 | 1359 | | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
1362 | | - | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
1371 | 1360 | | |
1372 | 1361 | | |
1373 | | - | |
1374 | | - | |
1375 | | - | |
1376 | | - | |
1377 | | - | |
1378 | | - | |
1379 | | - | |
1380 | | - | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
1381 | 1369 | | |
1382 | 1370 | | |
1383 | | - | |
1384 | | - | |
1385 | | - | |
1386 | | - | |
1387 | | - | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
1388 | 1379 | | |
1389 | | - | |
1390 | | - | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
1391 | 1384 | | |
1392 | 1385 | | |
1393 | 1386 | | |
| |||
1579 | 1572 | | |
1580 | 1573 | | |
1581 | 1574 | | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
1582 | 1583 | | |
1583 | | - | |
1584 | | - | |
| 1584 | + | |
1585 | 1585 | | |
1586 | | - | |
1587 | | - | |
1588 | | - | |
1589 | | - | |
1590 | | - | |
1591 | | - | |
1592 | | - | |
1593 | | - | |
1594 | | - | |
1595 | | - | |
1596 | | - | |
1597 | | - | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
1598 | 1589 | | |
1599 | 1590 | | |
1600 | 1591 | | |
1601 | | - | |
1602 | | - | |
1603 | | - | |
1604 | | - | |
| 1592 | + | |
1605 | 1593 | | |
1606 | | - | |
1607 | | - | |
1608 | | - | |
1609 | | - | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
1610 | 1605 | | |
1611 | | - | |
1612 | | - | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
1613 | 1610 | | |
0 commit comments