Speed up native types
See original GitHub issueThere is a good opportunity to speed up some of the functions, when they are a native type (array string, TypedArray). For example:
import ensureIterable from './internal/ensure-iterable'
export default function size (iterable) {
if (typeof iterable === 'string') return iterable.length
let size = 0
// eslint-disable-next-line
for (const _ of ensureIterable(iterable)) {
size++
}
return size
}
There is an important caveat though. It is important to decide a cut-off point based on the size of the data structure: It can be a nice improvement using array.prototype.map whenever the size of the array is not big. But it can blow up the memory otherwise.
Issue Analytics
- State:
- Created 5 years ago
- Comments:25 (2 by maintainers)
Top Results From Across the Web
Java Buffer types versus native arrays: which is faster?
Java has native arrays (e.g., the int[] type). ... That is, arrays are over 4 times faster than IntBuffers in this test.
Read more >Performance of built-in types : char vs short vs int vs. float ...
Different size integer types: Typically, CPUs are fastest at operating on integers of their native word size (with some caveats about 64-bit ...
Read more >Speeding Up for Naive Algorithm
Honestly, the main cause of the speedup is called vectorization, which the compiler does automatically due to the pragmas. After blindly trying for...
Read more >Best Tricks to Speed Up Your React Native App
We have covered some simple and amazing tricks that you can use to make your React Native app run faster and enhance the...
Read more >Performance tips and tricks - Mypyc - Read the Docs
If you are speeding up existing code, understanding where time is spent is important. Mypyc speeds up code that you compile. If most...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Regarding the sparse array earlier,
Array.from
(and/or spread operator ([...arr]
)) should be able to fix the problem.Array.from
should also be used on typed arrays (Int8Array
,Int16Array
, etc.) if we were to call.map()
because despite typed arrays don’t have holes, their map functions never returns array of other types.As for
.filter()
on typed arrays, you can call it directly without cloning.I am going to rename it to
TypedArrayProto
. It is explained here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#Description