jsoftware / jsource

J engine source mirror
Other
657 stars 90 forks source link

Use inline caching for i. et al to avoid condrange overhead #155

Open moon-chilled opened 2 years ago

moon-chilled commented 2 years ago

Associate a saturating counter with every call site telling whether it's worthwhile to do small-range or not. If it's predicted not worthwhile, skip condrange and go straight to building the hash table; range can be calculated at low cost while doing hash table, so we get feedback on if we got this wrong. If it is predicted worthwhile, also cache an approximate lower bound (often just 0, or the time when an initial measurement was taken, or w/e); if it appears stable (how to quantify this?), speculatively start building the small-range table right away and bail out if the range estimate was wrong.

Backoff in condrange can probably skipped, simplifying and possibly speeding up slightly.

moon-chilled commented 2 years ago

Perhaps also use to identify opportunities for reverse small-range where we wouldn't have otherwise considered it due to relative sizes?