|
| 1 | +#fencache design notes |
| 2 | +------------ |
| 3 | +* the key val storage option could perform better with equal buted inputs |
| 4 | +but is genrly hindered because arg/keys have to be stringified to be stowed |
| 5 | +and checked. |
| 6 | +a recent value buffering stage could improve the store |
| 7 | + |
| 8 | +* the double ring buffer storage could turn itself off on long runs of misses |
| 9 | +and resume after a resting count |
| 10 | +or could reduce its search and not write... |
| 11 | +basically a gism to giveup on repeat misses, and forget the tail or whole queue. |
| 12 | +since excessive misses entail excessive time consumed. |
| 13 | +little extra time may need added to the general case |
| 14 | +in order to count and react to successive excessive misses. |
| 15 | +eg to 20 misses of 20 entries. |
| 16 | +but the optimisations could choke general performance on problem patterns |
| 17 | +however they may greatly smooth reaction to the more common problem pattern |
| 18 | +of frequent cache miss runs. |
| 19 | + |
| 20 | +gism 1 |
| 21 | +after a number of long cache misses and writes, |
| 22 | +when rx gets to middle, split the cache and fill again |
| 23 | +as the low split of cache should be sorted infrequent anyway |
| 24 | +little point in keeping checking it |
| 25 | +gism 2 |
| 26 | +when miss rx!==split point, count it and write res |
| 27 | +when miss rx==split point, and count high, and if count then refill again |
| 28 | + |
| 29 | +problem cache strat is different for slow |
| 30 | + |
| 31 | +//---------------- |
| 32 | + |
| 33 | + |
| 34 | +//---------- |
| 35 | + |
| 36 | +# fencache |
| 37 | + |
| 38 | +Performance notes and data |
| 39 | +-------------------------- |
| 40 | + |
| 41 | +Example benchmark scores: |
| 42 | + |
| 43 | +Test of worst case (all misses) with random unique inputs |
| 44 | + |
| 45 | +fencached perfomance: |
| 46 | +``` |
| 47 | +Math.sin src performance, 30 Million func/s |
| 48 | + |
| 49 | +function csize speed % (of src) |
| 50 | +enSin 1 60.0 |
| 51 | +enSin 2 50.0 |
| 52 | +enSin 3 15.0 |
| 53 | +enSin 4 6.0 |
| 54 | +ensin 50 0.8 |
| 55 | +ensin 200 0.2 |
| 56 | +``` |
| 57 | + |
| 58 | +Test best case with 1 repeated input: |
| 59 | +``` |
| 60 | +Math.sin, 30 Million func/s |
| 61 | +A multi.trig function, 1.7 Million func/s |
| 62 | + |
| 63 | +function csize speed % |
| 64 | +enSin 1 220 |
| 65 | +enMTrig 1 3800 |
| 66 | +``` |
| 67 | + |
| 68 | +Test on 90 normally distributed distinct values |
| 69 | +``` |
| 70 | +Multi.trig function : 1.7 Mfunc/s |
| 71 | + |
| 72 | +function csize speed % |
| 73 | +enTrig 1 95 |
| 74 | +enTrig 2 95 |
| 75 | +enTrig 3 90 |
| 76 | +enTrig 12 110 |
| 77 | +enTrig 60 220 |
| 78 | +enTrig 100 310 |
| 79 | +enTrigx 0 840 |
| 80 | +``` |
| 81 | + |
| 82 | +Test a string processing functions on a selection of random length |
| 83 | +strings of upto 300 chars each, 200 of them repeated 4 times mixed up |
| 84 | +with 200 non repeated unique strings |
| 85 | +``` |
| 86 | +fast string process function : 130 Million func/s |
| 87 | +slow string process function : 5.9 Thousand func/s |
| 88 | + |
| 89 | +function csize speed % |
| 90 | +faststr 1 25.0 |
| 91 | +faststr 3 3.0 |
| 92 | +faststr 10 1.5 |
| 93 | +faststr 100 0.3 |
| 94 | +faststr 200 0.13 |
| 95 | +faststr 400 0.2 |
| 96 | +faststrx 0 8 |
| 97 | + |
| 98 | +slowstr 1 100 |
| 99 | +slowstr 3 100 |
| 100 | +slowstr 10 105 |
| 101 | +slowstr 100 160 |
| 102 | +slowstr 200 400 |
| 103 | +slowstr 400 4600 |
| 104 | +slowstrx 0 190000 (%!) |
| 105 | +``` |
| 106 | + |
| 107 | +Writing memory can often be a comparatively heavy nano operation, even when we are just duplicating references. Since memoizing necessitates extra memory writes as well as lookups, memoizing calculation results |
| 108 | + |
| 109 | +is only performant when there is |
| 110 | +some degree of repetition of parameters because keeping a larger cache size |
| 111 | +entails having more entries to check. Each cache search takes O(size) time |
| 112 | +for every miss. Fencache optimises lightly by floating results toward the head |
| 113 | +of the list each time they are recalled. This greatly suits unevenly distributed |
| 114 | +parameter sets and only marginally slows worst case. |
0 commit comments