This said, in the case of `case-fold-search` I think there's a simpler
solution: make it "buffer-local only", meaning that let-binding it
affects only the current buffer (rather than affecting all the buffers
which have not made it buffer-local yet).
Wouldn't that be a breaking change? And a non-obvious one.
Yup.
E.g. company-dabbrev-code creates a dynamic binding for case-fold-search in
one place and then calls a function (company-dabbrev--search) that iterates
across all buffers with re-search-forward.
I think we call this collateral damage.
My suggestion was indeed not completely serious, tho I do think in the
long run it's what we should do.
BTW, regarding making BVAR slower, we could reduce its cost by
introducing two versions of BVAR, so we only pay the price when
accessing one of the problematic variables like `case-fold-search`.