question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Speed up native types

See original GitHub issue

There 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:closed
  • Created 5 years ago
  • Comments:25 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
KSXGitHubcommented, Dec 22, 2018

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.

0reactions
sithmelcommented, Dec 29, 2018
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found