BOOLEAN_TO_JSVAL
DOUBLE_TO_JSVAL
INT_FITS_IN_JSVAL
INT_TO_JSVAL
JS::Add*Root
JS::AutoIdArray
JS::AutoSaveExceptionState
JS::AutoValueArray
JS::AutoVectorRooter
JS::BooleanValue
JS::Call
JS::CallArgs
JS::CloneFunctionObject
JS::Compile
JS::CompileFunction
JS::CompileOffThread
JS::CompileOptions
JS::Construct
JS::CreateError
JS::CurrentGlobalOrNull
JS::DeflateStringToUTF8Buffer
JS::DoubleNaNValue
JS::DoubleValue
JS::Evaluate
JS::FalseValue
JS::Float32Value
JS::GetDeflatedUTF8StringLength
JS::GetFirstArgumentAsTypeHint
JS::GetSelfHostedFunction
JS::Handle
JS::HandleValueArray
JS::IdentifyStandardInstance
JS::Int32Value
JS::IsCallable
JS::MutableHandle
JS::NewFunctionFromSpec
JS::NullHandleValue
JS::NullValue
JS::NumberValue
JS::ObjectOrNullValue
JS::ObjectValue
JS::OrdinaryToPrimitive
JS::PersistentRooted
JS::PropertySpecNameEqualsId
JS::PropertySpecNameIsSymbol
JS::PropertySpecNameToPermanentId
JS::ProtoKeyToId
JS::Remove*Root
JS::Rooted
JS::SetLargeAllocationFailureCallback
JS::SetOutOfMemoryCallback
JS::SourceBufferHolder
JS::StringValue
JS::SymbolValue
JS::ToBoolean
JS::ToInt32
JS::ToInt64
JS::ToNumber
JS::ToPrimitive
JS::ToString
JS::ToUint16
JS::ToUint32
JS::ToUint64
JS::TrueHandleValue
JS::TrueValue
JS::UndefinedHandleValue
JS::UndefinedValue
JS::Value
JSAutoByteString
JSAutoCompartment
JSBool
JSCheckAccessOp
JSClass
JSClass.call
JSClass.flags
JSConstDoubleSpec
JSConvertOp
JSDeletePropertyOp
JSEnumerateOp
JSErrorFormatString
JSErrorReport
JSExceptionState
JSExnType
JSExtendedClass
JSExtendedClass.outerObject
JSExtendedClass.wrappedObject
JSFUN_BOUND_METHOD
JSFUN_GLOBAL_PARENT
JSFastNative
JSFinalizeOp
JSFreeOp
JSFunction
JSFunctionSpec
JSGetObjectOps
JSHasInstanceOp
JSID_EMPTY
JSID_IS_EMPTY
JSID_IS_GCTHING
JSID_IS_INT
JSID_IS_STRING
JSID_IS_SYMBOL
JSID_IS_VOID
JSID_IS_ZERO
JSID_VOID
JSIdArray
JSIteratorOp
JSMarkOp
JSNative
JSNewEnumerateOp
JSNewResolveOp
JSObject
JSObjectOp
JSObjectOps.defaultValue
JSObjectOps.defineProperty
JSObjectOps.destroyObjectMap
JSObjectOps.dropProperty
JSObjectOps.enumerate
JSObjectOps.getAttributes
JSObjectOps.getProperty
JSObjectOps.getRequiredSlot
JSObjectOps.lookupProperty
JSObjectOps.newObjectMap
JSObjectOps.setProto
JSObjectPrincipalsFinder
JSPRINCIPALS_HOLD
JSPrincipals
JSPrincipalsTranscoder
JSProperty
JSPropertyDescriptor
JSPropertyOp
JSPropertySpec
JSProtoKey
JSReserveSlotsOp
JSResolveOp
JSRuntime
JSSecurityCallbacks.contentSecurityPolicyAllows
JSString
JSStringFinalizer
JSTraceOp
JSType
JSVAL_IS_BOOLEAN
JSVAL_IS_DOUBLE
JSVAL_IS_GCTHING
JSVAL_IS_INT
JSVAL_IS_NULL
JSVAL_IS_NUMBER
JSVAL_IS_OBJECT
JSVAL_IS_PRIMITIVE
JSVAL_IS_STRING
JSVAL_IS_VOID
JSVAL_LOCK
JSVAL_NULL
JSVAL_ONE
JSVAL_TO_BOOLEAN
JSVAL_TO_DOUBLE
JSVAL_TO_GCTHING
JSVAL_TO_INT
JSVAL_TO_OBJECT
JSVAL_TO_STRING
JSVAL_TRUE
JSVAL_UNLOCK
JSVAL_VOID
JSVAL_ZERO
JSVersion
JSXDRObjectOp
JS_ASSERT_STRING_IS_FLAT
JS_Add*Root
JS_AddArgumentFormatter
JS_AddExternalStringFinalizer
JS_AddFinalizeCallback
JS_AliasElement
JS_AliasProperty
JS_AlreadyHasOwnProperty
JS_BeginRequest
JS_BindCallable
JS_BufferIsCompilableUnit
JS_CStringsAreUTF8
JS_CallFunction
JS_CheckAccess
JS_CheckForInterrupt
JS_ClearContextThread
JS_ClearDateCaches
JS_ClearNewbornRoots
JS_ClearNonGlobalObject
JS_ClearPendingException
JS_ClearRegExpStatics
JS_ClearScope
JS_CloneFunctionObject
JS_CompareStrings
JS_CompileFileHandleForPrincipals
JS_CompileFileHandleForPrincipalsVersion
JS_CompileFunction
JS_CompileFunctionForPrincipals
JS_CompileScript
JS_CompileScriptForPrincipals
JS_CompileUCFunctionForPrincipalsVersion
JS_CompileUTF8File
JS_CompileUTF8FileHandle
JS_ConcatStrings
JS_ConstructObject
JS_ContextIterator
JS_ConvertArguments
JS_ConvertArgumentsVA
JS_ConvertValue
JS_DecompileFunction
JS_DecompileFunctionBody
JS_DecompileScript
JS_DecompileScriptObject
JS_DeepFreezeObject
JS_DefaultValue
JS_DefineConstDoubles
JS_DefineElement
JS_DefineFunction
JS_DefineFunctions
JS_DefineObject
JS_DefineOwnProperty
JS_DefineProperties
JS_DefineProperty
JS_DefinePropertyWithTinyId
JS_DeleteElement
JS_DeleteElement2
JS_DeleteProperty
JS_DeleteProperty2
JS_DestroyContext
JS_DestroyIdArray
JS_DestroyRuntime
JS_DestroyScript
JS_DoubleIsInt32
JS_DoubleToInt32
JS_DropExceptionState
JS_DumpHeap
JS_DumpNamedRoots
JS_EncodeCharacters
JS_EncodeString
JS_EncodeStringToBuffer
JS_EnterCompartment
JS_EnterCrossCompartmentCall
JS_EnterLocalRootScope
JS_Enumerate
JS_EnumerateDiagnosticMemoryRegions
JS_EnumerateResolvedStandardClasses
JS_EnumerateStandardClasses
JS_ErrorFromException
JS_EvaluateScript
JS_EvaluateScriptForPrincipals
JS_ExecuteRegExp
JS_ExecuteScript
JS_ExecuteScriptPart
JS_ExecuteScriptVersion
JS_FORGET_STRING_FLATNESS
JS_FS
JS_FileEscapedString
JS_Finish
JS_FlattenString
JS_FlushCaches
JS_ForgetLocalRoot
JS_ForwardGetPropertyTo
JS_FreezeObject
JS_GC
JS_GET_CLASS
JS_GetArrayLength
JS_GetArrayPrototype
JS_GetClass
JS_GetClassObject
JS_GetClassPrototype
JS_GetCompartmentPrivate
JS_GetConstructor
JS_GetContextPrivate
JS_GetContextThread
JS_GetDefaultFreeOp
JS_GetElement
JS_GetEmptyString
JS_GetEmptyStringValue
JS_GetErrorPrototype
JS_GetExternalStringClosure
JS_GetExternalStringFinalizer
JS_GetFlatStringChars
JS_GetFunctionArity
JS_GetFunctionCallback
JS_GetFunctionFlags
JS_GetFunctionId
JS_GetFunctionName
JS_GetFunctionObject
JS_GetFunctionPrototype
JS_GetFunctionScript
JS_GetGCParameter
JS_GetGlobalForCompartmentOrNull
JS_GetGlobalForObject
JS_GetGlobalForObject3
JS_GetGlobalForScopeChain
JS_GetGlobalObject
JS_GetImplementationVersion
JS_GetInstancePrivate
JS_GetInternedStringChars
JS_GetLatin1FlatStringChars
JS_GetLatin1InternedStringChars
JS_GetLatin1StringCharsAndLength
JS_GetLocaleCallbacks
JS_GetNaNValue
JS_GetObjectPrototype
JS_GetObjectRuntime
JS_GetOptions
JS_GetOwnPropertyDescriptor
JS_GetParent
JS_GetParentRuntime
JS_GetPendingException
JS_GetPositiveInfinityValue
JS_GetPrivate
JS_GetProperty
JS_GetPropertyAttributes
JS_GetPropertyAttrsGetterAndSetter
JS_GetPropertyDefault
JS_GetPropertyDescriptor
JS_GetPrototype
JS_GetRegExpFlags
JS_GetRegExpSource
JS_GetReservedSlot
JS_GetRuntime
JS_GetRuntimePrivate
JS_GetScopeChain
JS_GetSecurityCallbacks
JS_GetStringBytes
JS_GetStringCharAt
JS_GetStringChars
JS_GetStringCharsAndLength
JS_GetStringEncodingLength
JS_GetStringLength
JS_GetTwoByteExternalStringChars
JS_GetTypeName
JS_GetVersion
JS_HasArrayLength
JS_HasElement
JS_HasInstance
JS_HasOwnProperty
JS_HasProperty
JS_IdArrayGet
JS_IdArrayLength
JS_IdToProtoKey
JS_IdToValue
JS_Init
JS_InitCTypesClass
JS_InitClass
JS_InitStandardClasses
JS_InstanceOf
JS_InternJSString
JS_InternString
JS_IsArrayObject
JS_IsAssigning
JS_IsBuiltinEvalFunction
JS_IsBuiltinFunctionConstructor
JS_IsConstructing
JS_IsConstructing_PossiblyWithGivenThisObject
JS_IsConstructor
JS_IsExceptionPending
JS_IsExtensible
JS_IsExternalString
JS_IsGlobalObject
JS_IsIdentifier
JS_IsNative
JS_IsNativeFunction
JS_IsRunning
JS_IsStopIteration
JS_IterateCompartments
JS_LeaveCompartment
JS_LeaveCrossCompartmentCall
JS_LeaveLocalRootScope
JS_LeaveLocalRootScopeWithResult
JS_LinkConstructorAndPrototype
JS_Lock
JS_LockGCThing
JS_LookupElement
JS_LookupProperty
JS_LooselyEqual
JS_MakeStringImmutable
JS_MapGCRoots
JS_MaybeGC
JS_New
JS_NewArrayObject
JS_NewCompartmentAndGlobalObject
JS_NewContext
JS_NewDateObject
JS_NewDateObjectMsec
JS_NewDependentString
JS_NewDouble
JS_NewDoubleValue
JS_NewExternalString
JS_NewFunction
JS_NewGlobalObject
JS_NewNumberValue
JS_NewObject
JS_NewObjectForConstructor
JS_NewPlainObject
JS_NewPropertyIterator
JS_NewRegExpObject
JS_NewRuntime
JS_NewScriptObject
JS_NewStringCopyN
JS_NewStringCopyZ
JS_NewUCString
JS_NextProperty
JS_Now
JS_NumberValue
JS_ObjectIsDate
JS_ObjectIsFunction
JS_ObjectIsRegExp
JS_PSGS
JS_ParseJSON
JS_PopArguments
JS_PreventExtensions
JS_PropertyStub
JS_PushArguments
JS_PutEscapedString
JS_Remove*Root
JS_RemoveExternalStringFinalizer
JS_RemoveRootRT
JS_ReportError
JS_ReportErrorNumber
JS_ReportOutOfMemory
JS_ReportPendingException
JS_ResolveStandardClass
JS_RestoreExceptionState
JS_SET_TRACING_DETAILS
JS_SameValue
JS_SaveExceptionState
JS_SaveFrameChain
JS_ScheduleGC
JS_SealObject
JS_SetAllNonReservedSlotsToUndefined
JS_SetArrayLength
JS_SetBranchCallback
JS_SetCallReturnValue2
JS_SetCheckObjectAccessCallback
JS_SetCompartmentNameCallback
JS_SetContextCallback
JS_SetDefaultLocale
JS_SetDestroyCompartmentCallback
JS_SetElement
JS_SetErrorReporter
JS_SetExtraGCRoots
JS_SetFunctionCallback
JS_SetGCCallback
JS_SetGCParametersBasedOnAvailableMemory
JS_SetGCZeal
JS_SetGlobalObject
JS_SetICUMemoryFunctions
JS_SetInterruptCallback
JS_SetNativeStackQuota
JS_SetObjectPrincipalsFinder
JS_SetOperationCallback
JS_SetOptions
JS_SetParent
JS_SetPendingException
JS_SetPrincipalsTranscoder
JS_SetPrivate
JS_SetProperty
JS_SetPropertyAttributes
JS_SetPrototype
JS_SetRegExpInput
JS_SetScriptStackQuota
JS_SetThreadStackLimit
JS_SetVersion
JS_SetVersionForCompartment
JS_ShutDown
JS_StrictlyEqual
JS_StringEqualsAscii
JS_StringHasBeenInterned
JS_StringHasLatin1Chars
JS_StringIsFlat
JS_StringToVersion
JS_SuspendRequest
JS_THREADSAFE
JS_ThrowStopIteration
JS_ToggleOptions
JS_TracerInit
JS_TypeOfValue
JS_Unlock
JS_ValueToBoolean
JS_ValueToECMAInt32
JS_ValueToFunction
JS_ValueToId
JS_ValueToInt32
JS_ValueToNumber
JS_ValueToObject
JS_ValueToSource
JS_ValueToString
JS_VersionToString
JS_YieldRequest
JS_freeop
JS_malloc
JS_updateMallocCounter
OBJECT_TO_JSVAL
PRIVATE_TO_JSVAL
Property attributes
STRING_TO_JSVAL
Stored value
jschar
jsdouble
jsid
jsint
Note: This page is an in-progress documentation of JIT optimization strategies planned to support the "JIT Coach" feature intended for inclusion in Firefox developer tools. This page has two intended uses:
1. Provide a repository of JIT Optimization Strategy information which the JIT Coach tool can parse to display in its UI.
2. Provide a user-browsable documentation of optimization strategies, how they work, how they are defeated, and options for how to re-enable them.
SpiderMonkey's optimizing JIT, IonMonkey, uses various strategies to optimize operations. The most commonplace operations that are relevant for fast program execution are property accesses and function calls.
Optimization information is currently collected for the following operations:
obj.prop
)obj.prop = val
)obj[elemName]
)obj[elemName] = val
)func(...)
)At each operation site, IonMonkey tries a battery of strategies, from the most optimized but most restrictive to the least optimized but least restrictive. For each strategy attempted, its outcome is tracked. An outcome is either success or a reason why the strategy failed to apply.
This page documents the various optimization strategies and their outcomes. It provides information on what they attempt to do, what general level of speed-up they provide, what kind of program characteristics can prevent them from being used, and common ways to enable the engine to utilize that optimization.
Attempts to optimize an arguments.length
property access. This optimization only works if the arguments object is used in well-understood ways within the function. The function containing the arguments.length
is allowed to use the arguments object in the following ways without disabling this optimization:
arguments.length
arguments.callee
arguments[i]
arguments
into variables, as long as those variables cannot be accessed by any nested function, and as long as there exists no eval
anywhere within the function or nested function definitions.f.apply(obj, arguments)
If the function contains any use of the arguments
object that falls out of the cases defined above, this optimization will be suppressed. In particular, arguments
cannot be returned from the function, or passed as an argument into calls (except for the apply
case above).
Attempts to optimize an arguments.callee
property access. This optimization only works if the arguments object is used in well-understood ways within the function. The function containing the arguments.callee
is allowed to use the arguments object in the following ways without disabling this optimization:
arguments.length
arguments.callee
arguments[i]
arguments
into variables, as long as those variables cannot be accessed by any nested function, and as long as there exists no eval
anywhere within the function or nested function definitions.f.apply(obj, arguments)
If the function contains any use of the arguments
object that falls out of the cases defined above, this optimization will be suppressed. In particular, arguments
cannot be returned from the function, or passed as an argument into calls (except for the apply
example listed above).
Attempts to optimize an access to a property that seems to be a constant. It applies to property accesses on objects which are global-like in that there is only one instance of them per program. This includes global objects, object literals defined at the top-level of a script, and top-level function objects.
This optimization makes the assumption that a property that has not changed after it was first assigned, is likely a constant property. It then directly inlines the value of the property into hot code that accesses it. For example, in the following code:
var Constants = {};
Constants.N = 100;
function testArray(array) {
for (var i = 0; i < array.length; i++) {
if (array[i] > Constants.N)
return true;
}
return false;
}
Will have the loop compiled into the following when testArray
gets hot.
for (var i = 0; i < array.length; i++) {
if (array[i] > 100)
return true;
}
When this optimization is successful, property access is eliminated entirely and replaced with an inline constant.
Attempts to optimize reading a property that contains a uniquely-typed (or "singleton") object. With uniquely-typed objects, it is guaranteed that no other object has that same type. Unique (or "singleton") types are assigned to certain kinds of objects, like global objects, top-level functions, and object literals declared at the top-level of a script. If a property has always contained the same uniquely-typed object, then the engine can use the unique type to map back to a specific object, and eliminate the property access, replacing it with a constant reference to the object.
When this optimization is successful, property access is eliminated entirely and replaced with an inline constant. The different success and failure conditions are documented below:
Attempts to optimize a property access on window
which refers to a property on the global object.
Optimizes accesses to properties on TypedObjects.
Optimizes access to a well-known regular property on an object. For this optimization to succeed, the property needs to be well-defined on the object. For objects constructed by constructor functions, this means that the property needs to be defined in the constructor, before any complex logic occurs within the constructor.
This is the best case for a regular "field" type property that is not turned into a constant. It compiles down to a single CPU-level load instruction.
function SomeConstructor() {
this.x = 10; // x is a definite slot property
this.y = 10; // y is a definite slot property
someComplicatedFunctionCall();
this.z = 20; // z is not a definite slot property.
}
In the above example, the properties x
and y
can always be determined to exist on any instance of SomeConstructor
at definite locations, allowing the engine to infer deterministically the position of x
without a shape guard.
This optimization can fail for a number of reasons. If the types observed at the property access are polymorphic (more than one type), this optimization cannot succeed. Furthermore, even if the object type is monomorphic, the optimization will fail if the property being accessed is not a definite slot as described above.
Similar to GetProp_DefiniteSlot
. Unboxed property reads are possible on properties which satisfy all the characteristics of a definite slot, and additionally have been observed to only store values of one kind of value.
Consider the following constructor:
function Point(x, y) {
this.x = x;
this.y = y;
}
If only integers are ever stored in the x
and y
properties, then the instances of Point
will be represented in an "unboxed" mode - with the property values stored as raw 4-byte values within the object.
Objects which have the unboxed optimization are more compact.
Optimizes access to properties which are implemented by a getter function, where the getter is shared between multiple types.
This optimization applies most often when the property access site is polymorphic, but all the object types are derived variants of a single base class, where the property access refers to a getter on the base class.
Consider the following example: function Base() {} Base.prototype = { get x() { return 3; } };
function Derived1() {}
Derived1.prototype = Object.create(Base.prototype);
function Derived2() {}
Derived1.prototype = Object.create(Base.prototype);
If a property access for d.x
sees only instances of both Derived1
and Derived2
for d
, it can optimize the access to x
to a call to the getter function defined on Base
.
This optimization applies to shared getters on both pure JS objects as well as DOM objects.
Optimizes a polymorphic property access where there are only a few different types of objects seen, and the property on all of the different types is determinable through a shape-check.
If a property access is monomorphic and the property's location is determinable from the object's shape, but the property is not definite (see: GetProp_DefiniteProperty), then this optimization may be used.
Alternatively, if the property access is polymorphic, but only has a few different shapes observed at the access site, this optimization may be used.
This optimization compiles down to one or more shape-guarded direct loads from the object. The following pseudocode describes the kind of machine code generated by this optimization:
if obj.shape == Shape1 then
obj.slots[0]
elif obj.shape == Shape2 then
obj.slots[5]
elif obj.shape == Shape3 then
obj.slots[2]
...
end
Attempts to optimize a situation where a property access of the form window.PROP
can be directly translated into a property access on the inner global object.
This optimization will always fail on property accesses which are not on the window object.
It is useful because accessing global names via the 'window' object is a common idiom in web programming.
This is the worst-case scenario for a property access optimization. This strategy is used when all the others fail. The engine simply inserts an inline cache at the property access site.
Inline caches start off as a jump to a separate piece of code called a "fallback". The fallback calls into the interpreter VM (which is very slow) to perform the operation, and then decides if the operation can be optimized in that particular case. If so, it generates a new "stub" (or freestanding piece of jitcode) and changes the inline cache to jump to the stub. The stub attempts to optimize further occurrences of that same kind of operation.
Inline caches are an order of magnitude slower than the other optimization strategies, and are an indication that the type inference engine has failed to collect enough information to guide the optimization process.
Optimizes access to properties which are implemented by a setter function, where the setter is shared between multiple types.
This optimization applies most often when the property access site is polymorphic, but all the object types are derived variants of a single base class, where the property access refers to a setter on the base class.
Consider the following example: function Base() {} Base.prototype = { set x(val) { ... } };
function Derived1() {}
Derived1.prototype = Object.create(Base.prototype);
function Derived2() {}
Derived1.prototype = Object.create(Base.prototype);
If a property write for d.x = val
sees only instances of both Derived1
and Derived2
for d
, it can optimize the write to x
to a call to the setter function defined on Base
.
This optimization applies to shared setters on both pure JS objects as well as DOM objects.
Optimizes accesses to properties on TypedObjects.
Optimizes a write to a well-known regular property on an object. For this optimization to succeed, the property needs to be well-defined on the object. For objects constructed by constructor functions, this means that the property needs to be defined in the constructor, before any complex logic occurs within the constructor.
This is the best case for a regular "field" type property that is not turned into a constant. It compiles down to a single CPU-level load instruction.
function SomeConstructor() {
this.x = 10; // x is a definite slot property
this.y = 10; // y is a definite slot property
someComplicatedFunctionCall();
this.z = 20; // z is not a definite slot property.
}
In the above example, the properties x
and y
can always be determined to exist on any instance of SomeConstructor
at definite locations, allowing the engine to infer deterministically the position of x
without a shape guard.
This optimization can fail for a number of reasons. If the types observed at the property access are polymorphic (more than one type), this optimization cannot succeed. Furthermore, even if the object type is monomorphic, the optimization will fail if the property being written is not a definite slot as described above.
Similar to SetProp_DefiniteSlot
. Unboxed property writes are possible on properties which satisfy all the characteristics of a definite slot, and additionally have been observed to only store values of one kind of value.
Consider the following constructor:
function Point(x, y) {
this.x = x;
this.y = y;
}
If only integers are ever stored in the x
and y
properties, then the instances of Point
will be represented in an "unboxed" mode - with the property values stored as raw 4-byte values within the object.
Objects which have the unboxed optimization are more compact.
Optimizes a polymorphic property write where there are only a few different types of objects seen, and the property on all of the different types is determinable through a shape-check.
If a property write is monomorphic and the property's location is determinable from the object's shape, but the property is not definite (see: GetProp_DefiniteProperty), then this optimization may be used.
Alternatively, if the property write is polymorphic, but only has a few different shapes observed at the access site, this optimization may be used.
This optimization compiles down to one or more shape-guarded direct stores to the object. The following pseudocode describes the kind of machine code generated by this optimization:
if obj.shape == Shape1 then
obj.slots[0] = val
elif obj.shape == Shape2 then
obj.slots[5] = val
elif obj.shape == Shape3 then
obj.slots[2] = val
...
end
This is the worst-case scenario for a property access optimization. This strategy is used when all the others fail. The engine simply inserts an inline cache at the property write site.
Inline caches start off as a jump to a separate piece of code called a "fallback". The fallback calls into the interpreter VM (which is very slow) to perform the operation, and then decides if the operation can be optimized in that particular case. If so, it generates a new "stub" (or freestanding piece of jitcode) and changes the inline cache to jump to the stub. The stub attempts to optimize further occurrences of that same kind of operation.
Inline caches are an order of magnitude slower than the other optimization strategies, and are an indication that the type inference engine has failed to collect enough information to guide the optimization process.
Attempts to optimized element accesses on array Typed Objects.
Attempts to optimize element accesses on densely packed array objects. Dense arrays are arrays which do not have any 'holes'. This means that the array has valid values for all indexes from 0
to length-1
.
Attempts to optimize element accesses on a typed array that can be determined to always refer to the same array object. If this optimization succeeds, the 'array' object is treated as a constant, and is not looked up or retrieved from a variable.
Attempts to optimize element accesses on a typed array.
Attempts to optimize element accesses on a string.
Attempts to optimize element accesses on the arguments
special object available in functions. This optimization only works if the arguments object is used in well-understood ways within the function. The function containing the arguments.length
is allowed to use the arguments object in the following ways without disabling this optimization:
arguments.length
arguments.callee
arguments[i]
arguments
into variables, as long as those variables cannot be accessed by any nested function, and as long as there exists no eval
anywhere within the function or nested function definitions.f.apply(obj, arguments)
If the function contains any use of the arguments
object that falls out of the cases defined above, this optimization will be suppressed. In particular, arguments
cannot be returned from the function, or passed as an argument into calls (except for the apply
case above).
Similar to GetEelem_Arguments, but optimizes cases where the access on arguments
is happening within an inlined function. In these cases, an access of the form arguments[i]
can be directly translated into a direct reference to the corresponding argument value in the inlined call.
Consider the following: function foo(arg) { return bar(arg, 3); } function bar() { return arguments[0] + arguments[1]; }
In the above case, if foo
is compiled with Ion, and the call to bar
is inlined, then this optimization can transform the entire procedure to the following pseudo-code:
compiled foo(arg):
// inlined call to bar(arg, 3) {
return arg + 3;
// }
This is the worst-case scenario for an element access optimization. This strategy is used when all the others fail. The engine simply inserts an inline cache at the property write site.
Inline caches start off as a jump to a separate piece of code called a "fallback". The fallback calls into the interpreter VM (which is very slow) to perform the operation, and then decides if the operation can be optimized in that particular case. If so, it generates a new "stub" (or freestanding piece of jitcode) and changes the inline cache to jump to the stub. The stub attempts to optimize further occurrences of that same kind of operation.
Inline caches are an order of magnitude slower than the other optimization strategies, and are an indication that the type inference engine has failed to collect enough information to guide the optimization process.
Attempts to optimized element writes on array Typed Objects.
Attempts to optimize element writes on a typed array that can be determined to always refer to the same array object. If this optimization succeeds, the 'array' object is treated as a constant, and is not looked up or retrieved from a variable.
Attempts to optimize element writes on a typed array.
Attempts to optimize element writes on densely packed array objects. Dense arrays are arrays which do not have any 'holes'. This means that the array has valid values for all indexes from 0
to length-1
.
Attempts to optimize element writes to the arguments
special object available in functions. This optimization only works if the arguments object is used in well-understood ways within the function. The function containing the arguments.length
is allowed to use the arguments object in the following ways without disabling this optimization:
arguments.length
arguments.callee
arguments[i]
arguments
into variables, as long as those variables cannot be accessed by any nested function, and as long as there exists no eval
anywhere within the function or nested function definitions.f.apply(obj, arguments)
If the function contains any use of the arguments
object that falls out of the cases defined above, this optimization will be suppressed. In particular, arguments
cannot be returned from the function, or passed as an argument into calls (except for the apply
case above).
This is the worst-case scenario for a element write optimization. This strategy is used when all the others fail. The engine simply inserts an inline cache at the property write site.
Inline caches start off as a jump to a separate piece of code called a "fallback". The fallback calls into the interpreter VM (which is very slow) to perform the operation, and then decides if the operation can be optimized in that particular case. If so, it generates a new "stub" (or freestanding piece of jitcode) and changes the inline cache to jump to the stub. The stub attempts to optimize further occurrences of that same kind of operation.
Inline caches are an order of magnitude slower than the other optimization strategies, and are an indication that the type inference engine has failed to collect enough information to guide the optimization process.
A function call f(x)
usually pushes a frame onto the call stack. Inlining a call site conceptually copies the body of the callee function and pastes it in place of the call site and avoids pushing a new execution frame. Usually, hot functions do well to be inlined. This is one of the most important optimizations the JIT performs.
Ion inlines both interpreted (i.e., written in JavaScript) functions and native (i.e., built-ins such as Math.sin
implemented in C++).
A successfully inlined call site has the outcome Inlined.
Failure to inline comes in two flavors: unable (e.g., unable to determine exact callee) and unwilling (e.g., heuristics concluded that the time-space tradeoff will not pay off).