Each term has an ordered "postings list" of documents e.g.
foo -> 1, 7, 9, 12, 32, 44, ......
bar -> 41, 44, 99
If your query has a must clause for bar and the foo is optional then a bool query can tell the optional foo clause to efficiently skip reading over anything less than 41. The lists of doc ids are encoded in blocks that support skipping over whole chunks of these posting lists.
Also - if track_total_hits is false then non-competitive scoring documents can be skipped over. When bar is rare and we've already matched enough high-quality docs then the bool query can stop asking for more foo matches if that is a boring common word because we know these matches aren't going to be interesting enough to make the top results.