2 ms·
Higher level languages often use complex data structures at runtime that are a maze of pointers and thus suffer from bad cache locality. Such languages benefit
by samus 6y ago
Higher level languages often use complex data structures at runtime that are a maze of pointers and thus suffer from bad cache locality. Such languages benefit the most from language-specific high-level optimizations. Haskell for example uses strictness analysis to eliminate pointless lazy evaluation, and loop fusion to combine calls to `filter`, `map` and friends, thereby avoiding building up intermediary lists.
A compiler can do very little for dynamic languages. It could try to apply high-level optimizations, but as you say they are few and between, and hard. A Just-in-time compiler that optimizes hot path at runtime is usually the way to go. Unfortunately, they are quite a bit more complex. Most dynamic languages did not have them for a long time.