Javascript Performance

Data Structures

  • Prefer sorted array for O(n log n).

Engine Optimizations

Slow (HashTable):

{
    '1': 10,
    '2': 20,
    '3': 30,
}

Faster (Array):

{
    '0': 10,
    '1': 20,
    '2': 30,
}

Changing the index to ‘0’ is faster because the array implementation is faster than HashTable.

Source: Fast By Default: Algorithmic Performance Optimization in Practice