| Summary: | [JSC] Add fast path to TypedArray.from | ||||||
|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Jarred Sumner <jarred> | ||||
| Component: | JavaScriptCore | Assignee: | Yusuke Suzuki <ysuzuki> | ||||
| Status: | RESOLVED FIXED | ||||||
| Severity: | Normal | CC: | andre.bargull, saam, webkit-bug-importer, ysuzuki | ||||
| Priority: | P2 | Keywords: | InRadar | ||||
| Version: | WebKit Nightly Build | ||||||
| Hardware: | Unspecified | ||||||
| OS: | Unspecified | ||||||
| See Also: |
https://bugs.webkit.org/show_bug.cgi?id=239891 https://bugs.webkit.org/show_bug.cgi?id=240290 |
||||||
| Attachments: |
|
||||||
|
Description
Jarred Sumner
2022-04-30 21:30:21 PDT
Pull request: https://github.com/WebKit/WebKit/pull/564 Right condition to take this fast path is actually subtle :) BTW, it seems that SpiderMonkey and V8 optimize this function incorrectly. The following test pass only in JSC (and from the spec, JSC's behavior is correct since we use ArrayIterator, which uses "length" property, not TypedArrayLength).
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var array = new Uint8Array(128);
Reflect.defineProperty(array, 'length', {
value: 42
});
var result = Uint8Array.from(array);
shouldBe(result.length, 42);
Committed 252976@main (1b440efcb4ae): <https://commits.webkit.org/252976@main> Reviewed commits have been landed. Closing PR #564 and removing active labels. (In reply to Yusuke Suzuki from comment #4) > BTW, it seems that SpiderMonkey and V8 optimize this function incorrectly. > The following test pass only in JSC (and from the spec, JSC's behavior is > correct since we use ArrayIterator, which uses "length" property, not > TypedArrayLength). It's actually the other way around. JSC is incorrectly using the "length" [1] property, whereas the spec mandates that for objects with a [[TypedArrayName]] internal slot, the [[ArrayLength]] internal slot is read [2]. :-) [1] https://github.com/WebKit/WebKit/blob/3f019cf4b5d2b381db5af9d2751583f7871ba8bf/Source/JavaScriptCore/builtins/ArrayIteratorPrototype.js#L53 [2] https://tc39.es/ecma262/#sec-createarrayiterator (In reply to André Bargull from comment #6) > (In reply to Yusuke Suzuki from comment #4) > > BTW, it seems that SpiderMonkey and V8 optimize this function incorrectly. > > The following test pass only in JSC (and from the spec, JSC's behavior is > > correct since we use ArrayIterator, which uses "length" property, not > > TypedArrayLength). > > It's actually the other way around. JSC is incorrectly using the "length" > [1] property, whereas the spec mandates that for objects with a > [[TypedArrayName]] internal slot, the [[ArrayLength]] internal slot is read > [2]. :-) > > [1] > https://github.com/WebKit/WebKit/blob/ > 3f019cf4b5d2b381db5af9d2751583f7871ba8bf/Source/JavaScriptCore/builtins/ > ArrayIteratorPrototype.js#L53 > [2] https://tc39.es/ecma262/#sec-createarrayiterator Oh, interesting. We can make the implementation simpler. (In reply to Yusuke Suzuki from comment #7) > (In reply to André Bargull from comment #6) > > (In reply to Yusuke Suzuki from comment #4) > > > BTW, it seems that SpiderMonkey and V8 optimize this function incorrectly. > > > The following test pass only in JSC (and from the spec, JSC's behavior is > > > correct since we use ArrayIterator, which uses "length" property, not > > > TypedArrayLength). > > > > It's actually the other way around. JSC is incorrectly using the "length" > > [1] property, whereas the spec mandates that for objects with a > > [[TypedArrayName]] internal slot, the [[ArrayLength]] internal slot is read > > [2]. :-) > > > > [1] > > https://github.com/WebKit/WebKit/blob/ > > 3f019cf4b5d2b381db5af9d2751583f7871ba8bf/Source/JavaScriptCore/builtins/ > > ArrayIteratorPrototype.js#L53 > > [2] https://tc39.es/ecma262/#sec-createarrayiterator > > Oh, interesting. We can make the implementation simpler. Will be fixed in https://github.com/WebKit/WebKit/pull/3038, it makes implementation simpler! |