Query 2 is only 429 lines, but expected to grow as more features are added.
I had thoughts of adding super-optimizations, like map-map-map and where-map-map-where, but I think that's a bit overkill, yet totally doable.
Query 2 does this:
A sequence like this: Map.Map.Where/Filter.Each();
Turns into this chain:
Map2Node -> WhereNode -> EachNode -> null
Map2Node is an optimization. Where/Filter type nodes breaks the chain early if they fail. This is not recursive or I'll run out of stack space, so it pops the chain back (via return) and restarts it, iterating to the next value. Now, it returns the successful value if it made it to an 'end node' like Each or All, or undefined if it stops part-way (Filter, Uniq etc). Checking for Undefined can aid in performing queries that involve 'contains' and 'every'. The optimizations work by reducing unnecessary node traversals and function stack creations. The optimizations speedups hit the limit of actually doing the raw for loop, and so with a sufficient optimizer I think the complexity is equal to a hand written for loop (with the only downside of traversing nodes added to the mix).
To run it, all I do is this:
var i = -1, l = 25000000;
while (i++ < l && !Env.stop) r.exec(a[i]);
So it has a very lightweight loop on the inside, and the only overhead is node switching. Things like break and continue are handled with node chains returning early and setting the environment stop element to true.
Edit:
I was able to get Lazy to work in Sphere 1.6, it turns out the number of things I had to change was small.
How's the performance of the two? Well... The same! Everything I threw at it, they performed the same. For longer queries I notice Query 2 was always faster, but for single queries, Lazy won. To get an idea:
On map, Lazy was 1.3 times faster.
On map-map, Query2 was 2.0 times faster.
On map-map-map, Query2 was 2.2 times faster.
On map-map-map-map, Query2 was 2.7 times faster.
So, longer queries, especially the optimized cases with map-map, Query2 started to really haul ass. But, this is like 'best results' stuff and totally not typical. For typical queries (like yours with isInt and div3) the two performed the same (with Query2 slightly faster).