As demonstrated by http://jsperf.com/base58-array-ops, and even a basic understanding should make it clear, using unshift is much slower than using push in Array operations as each unshift is an O(n) operation.
This change just reverses the operation order on the array so as push becomes possible, with a single O(n) reversal done at the end of the function.
On Chrome, this gives a slight (~10-15%) improvement, but on Firefox 30 it gives up to a 50% improvement in ops/sec.
Coverage remained the same when pulling dede3a76de3320e2ee6c9464a934a4a2473b0197 on dcousens:opti into 7d29b7784a464b336de0a4b85f6d580588555882 on cryptocoinjs:master.
Coverage remained the same when pulling fd805f7a732fa28ee57e364b4791f86ca3b462f9 on dcousens:opti into 7d29b7784a464b336de0a4b85f6d580588555882 on cryptocoinjs:master.
As demonstrated by http://jsperf.com/base58-array-ops, and even a basic understanding should make it clear, using
unshift
is much slower than usingpush
inArray
operations as eachunshift
is an O(n) operation.This change just reverses the operation order on the array so as
push
becomes possible, with a single O(n) reversal done at the end of the function. On Chrome, this gives a slight (~10-15%) improvement, but on Firefox 30 it gives up to a 50% improvement in ops/sec.