I just noticed a possible optimization opportunity in PersistentBag that should save a few cycles. The idea is to:
introduce a check for empty inputs
desugar the Stream API to a vanilla loop
In an isolated benchmark this shows the following improvements for a non empty list:
For an empty list the following results are produced (testNew being the one with the additional isEmpty() check):
PR is attached.