private List<Pair<S, List<C>>> filterAndModulate(final Collection<S> original) {
        if (comparators.isEmpty())
            this.comparators.add(new Pair<>(new IdentityTraversal(), (Comparator) Order.asc));

        // detect shuffle and optimize by either ignoring other comparators if shuffle is last or
        // ignoring comparators that are shuffles if they are in the middle
        final boolean isShuffle = (Comparator) this.comparators.get(this.comparators.size() - 1).getValue1() == Order.shuffle;
        final List<Pair<Traversal.Admin<S, C>, Comparator<C>>> relevantComparators = isShuffle ?
                this.comparators :
                this.comparators.stream().filter(p -> (Comparator) p.getValue1() != Order.shuffle).collect(Collectors.toList());

        final List<Pair<S, List<C>>> filteredAndModulated = new ArrayList<>();
        final List<Traversal.Admin<S, C>> modulators = relevantComparators.stream().map(Pair::getValue0).collect(Collectors.toList());
        for (S s : original) {
            // filter out unproductive by()
            final List<C> modulations = modulators.stream().map(t -> TraversalUtil.produce(s, t)).
                    filter(TraversalProduct::isProductive).
                    map(product -> (C) product.get()).collect(Collectors.toList());

            // when sizes arent the same it means a by() wasn't productive and it is ignored
            if (modulations.size() == modulators.size()) {
                filteredAndModulated.add(Pair.with(s, modulations));
            }
        }

        if (isShuffle) {
            Collections.shuffle(filteredAndModulated, random);
        } else {
            // sort the filter/modulated local list in place using the index of the modulator/comparators
            Collections.sort(filteredAndModulated, (o1, o2) -> {
                final List<C> modulated1 = o1.getValue1();
                final List<C> modulated2 = o2.getValue1();
                for (int ix = 0; ix < modulated1.size(); ix++) {
                    final int comparison = relevantComparators.get(ix).getValue1().compare(modulated1.get(ix), modulated2.get(ix));
                    if (comparison != 0)
                        return comparison;
                }

                return 0;
            });
        }

        return filteredAndModulated;
    }
Take the collection and apply modulators removing traversers that have modulators that aren't productive.
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderLocalStep.java