---
title: "Optimizing JavaScript Standard Library Functions in JSC"
description: "JavaScriptCore speeds up Function.prototype.toString by stacking several general optimizations that together reduce a call like f.toString() to a constant string."
url: "https://swe.quest/articles/optimizing-javascript-standard-library-functions-in-jsc-1faf7ca6f0ee5e50"
canonical: "https://webkit.org/blog/11934/optimizing-javascript-standard-library-functions-in-jsc/"
source: "WebKit"
published: "2021-07-28"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 6
tags: ["runtimes","compilers","javascript","browsers","performance"]
---

# Optimizing JavaScript Standard Library Functions in JSC

A post on [WebKit](https://swe.quest/sources/webkit.md), published 2021-07-28, 6 min read, Deep dive. Original: [https://webkit.org/blog/11934/optimizing-javascript-standard-library-functions-in-jsc/](https://webkit.org/blog/11934/optimizing-javascript-standard-library-functions-in-jsc/)

## Summary

JavaScriptCore speeds up Function.prototype.toString by stacking several general optimizations that together reduce a call like f.toString() to a constant string. The result is cached on the function object, watchpoints let the DFG/FTL speculate that f and f.toString never change, an intrinsic replaces the generic call with a FunctionToString instruction that loads the cached value inline with a C++ fallback, and the abstract interpreter constant-folds the load when the receiver is known. The walkthrough also contrasts C++ and JS-implemented builtins, noting that native builtins can't be inlined but intrinsics can still emit their fast paths.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [Compilers](https://swe.quest/tags/compilers.md) (Compilers & runtimes)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Browsers](https://swe.quest/tags/browsers.md) (Web & mobile)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- JIT compilation tiers ([easy posts on Compilers](https://swe.quest/tags/compilers.md?difficulty=easy))
- compiler intermediate representations
- JavaScript prototype semantics ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))

## Keywords

JavaScriptCore, WebKit, DFG, FTL, Function.prototype.toString, watchpoints, abstract interpretation

## Related posts

- [Bun v0.1.9](https://swe.quest/articles/bun-v0-1-9-4ecfe167e5b29929.md): Bun · 2022-08-18 · Medium · 3 min read · Runtimes & VMs, JavaScript, Zig, Performance engineering, Compilers
  Bun v0.1.9 starts using JavaScriptCore's DOMJIT API to JIT-optimize native functions, making \`ptr()\` in \`bun:ffi\` 6-10x faster and \`TextEncoder.encodeInto\` 1.5-5x faster.
- [How the Cinder JIT’s function inliner helps us optimize Instagram](https://swe.quest/articles/how-the-cinder-jit-s-function-inliner-helps-us-optimize-instagram-bec4e8e06857e7ce.md): Meta Engineering · 2022-05-02 · Hard · 13 min read · Compilers, Python, Runtimes & VMs, Performance engineering
  Cinder, Instagram's open-source CPython fork, ships a method-at-a-time JIT that lowers bytecode through HIR, SSA, LIR and register allocation to native code, removing interpreter dispatch and stack overhead.
- [Compile and run C in JavaScript](https://swe.quest/articles/compile-and-run-c-in-javascript-951e10ff9004c507.md): Bun · 2024-09-18 · Medium · 8 min read · JavaScript, C & C++, Runtimes & VMs, Performance engineering
  Bun v1.1.28 adds experimental \`cc\` in \`bun:ffi\`, which uses TinyCC to compile, link and relocate C in memory and generates inline wrappers that convert between JavaScriptCore values and C primitives with no dynamic dispatch.
- [Speculative Optimizations for WebAssembly using Deopts and Inlining](https://swe.quest/articles/speculative-optimizations-for-webassembly-using-deopts-and-inlining-bb89e7c53ac7945f.md): V8 · 2025-06-24 · Hard · 17 min read · WebAssembly, Compilers, Runtimes & VMs, Performance engineering
  V8 in Chrome M137 adds speculative call\_indirect inlining and deoptimization support for WebAssembly, using runtime call-target feedback gathered by the Liftoff baseline compiler so TurboFan can inline up to four likely callees behind cheap instance and target checks.
- [How we made JSON.stringify more than twice as fast](https://swe.quest/articles/how-we-made-json-stringify-more-than-twice-as-fast-a8feda7c2e371e2a.md): V8 · 2025-08-04 · Hard · 7 min read · Runtimes & VMs, JavaScript, Performance engineering, Browsers
  V8 more than doubled JSON.stringify throughput on the JetStream2 json-stringify-inspector benchmark by adding an iterative, side-effect-free fast path that skips the general serializer's defensive checks.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
