Repository navigation
fix: preserve sparse slots in optimized slice - #1335
nk-batman21 wants to merge 2 commits into
Conversation
|
I'm not sure whether sparse arrays are a necessarily sane concept in JavaScript, so I'd want to understand the performance ramifications first (the patch itself is small enough). |
|
c10aba9 keeps
|
|
@mweststrate yeah, I have very mixed feelings about all these array edge case PRs :( on the one hand I agree things "ought" to work the same as in vanilla JS, and most of the changes have been small. on the other hand... man there's a lot of edge cases and sometimes you gotta draw a line and say "nope we just don't handle that and also why would anyone do that in the first place". |
|
The discussion in #1019 makes the scope concern clear, and I agree that JavaScript parity alone isn't enough reason to add support. This PR came from a synthetic repro, with no reported application failure behind it, so I'm fine with closing it if sparse arrays remain outside the intended scope. |
|
@markerikson yeah I have two problems with it:
I think I'm going to introduce a new label "we-can-merge-this-if-someone-actually-cares-and-provides-a-real-life-use-case" |
|
@nk-batman21 thanks for elaborating. I'll add the label and can close after a while if it doesn't pop up for anyone. |
With
enableArrayMethods(),slice()fills sparse array slots withundefined. A subsequentslice().map(item => item.id)then throws on slots that nativemapwould skip.Preserve the empty slots while keeping selected objects as drafts. Regression tests cover full, bounded and negative-index slices, explicit
undefinedvalues, and mutations through the sliced objects.yarn test(3,872 source tests and 3,321 production-build tests passed, with eight existing skips in each suite; builds and Flow passed).git diff --check.