It’s an arbitrary problem, so you could argue that pre computation is fine but you need to assume a cold cache or whatever.
Preprocessing is always an option: just needs some ahead of time effort.
A hot cache for a 37GB file is not always an option.
Aka are you building a service or grep.