Bug 193764

Summary: Template Literal GC'ed Against Specs
Product: WebKit Reporter: Andrea Giammarchi <andrea.giammarchi>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: keith_miller, rniwa, ysuzuki
Priority: P2    
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
the alert shown on Safari Technology Preview none

Description Andrea Giammarchi 2019-01-24 01:29:36 PST
Created attachment 360000 [details]
the alert shown on Safari Technology Preview

Accordingly with Note 2 of ECMAScript Language Specification:
http://www.ecma-international.org/ecma-262/#sec-gettemplateobject

Each TemplateLiteral in the program code of a realm is associated with a unique template object that is used in the evaluation of tagged Templates (12.2.9.6).
The template objects are frozen and the same template object is used each time a specific tagged Template is evaluated.
Whether template objects are created lazily upon first evaluation of the TemplateLiteral or eagerly prior to first evaluation is an implementation choice that is not observable to ECMAScript code.

However, as you can easily test on this code pen https://codepen.io/WebReflection/pen/OdVrqN?editors=0010 , you will see an alert, at some point, demonstrating that the template literal has been collected and recreated, hence it's both not unique and also observable in terms of GC operation.

This happens in both latest Safari on macOS Mojave, and Safari Technology Preview, and it makes code relying on uniqueness of template literals incapable of performing well in Safari ('cause templates needs to be transformed per their value instead of their unique reference).

Please provide an ETA so I can also evaluate if I should penalize safari performance in various libraries based on that part of the specifications.
Comment 1 Ryosuke Niwa 2019-02-04 14:42:35 PST

*** This bug has been marked as a duplicate of bug 190756 ***