Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array-splice.html calcEditDistance can cause browser out-of-memory exception if compared lists are too large #5195

Closed
1 of 6 tasks
gopherkhan opened this issue Apr 16, 2018 · 2 comments

Comments

@gopherkhan
Copy link

I first encountered this bug when using an iron-list. See here:
PolymerElements/iron-list#518

Essentially, calcEditDistances creates an MxN diff space for compared arrays. If two arrays are sufficiently large, the algo can cause an out-of-memory exception in the browser.

In my tests, two 30,000 element lists became a 900,000,000 entity grid, and consumes 1gig of heap before crashing the browser.

                              old, oldStart, oldEnd) {
    // "Deletion" columns
    let rowCount = oldEnd - oldStart + 1;
    let columnCount = currentEnd - currentStart + 1;
    let distances = new Array(rowCount);

    // "Addition" rows. Initialize null column.
    for (let i = 0; i < rowCount; i++) { // crashes reliably here
      distances[i] = new Array(columnCount);
      distances[i][0] = i;
    }

Description

Live Demo

JsBin is not loading for me at the moment, but you can start here:
https://jsbin.com/lolekifale/4/edit?html,console,output

Tweak the click listener from:
list.splice('items', 49999, 0, ...items);

to

list.items = items;

Open your debugger to catch the OOM-exception in calcEditDistances

Alternatively you could supply two lists directly to the calcEditDistances function,

var listA = [30k elements];
var listB = [30k elements];
calcEditDistances(listA, 0, listA.length,
                              listB, 0, listB.length); 

And that should exhibit the same behavior.

I'm guessing some threshold should be in place for too-long comparisons, or that the algo should be skipped or somehow batched if the comparison space is too large.

Steps to Reproduce

See above.

Expected Results

No error is thrown

Actual Results

the whole page crashes.

Browsers Affected

  • Chrome
  • Firefox
  • Edge
  • Safari 9
  • Safari 8
  • IE 11

Versions

  • Polymer: vX.X.X
  • webcomponents: vX.X.X
@stale
Copy link

stale bot commented Mar 13, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 13, 2020
@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically closed after being marked stale. If you're still facing this problem with the above solution, please comment and we'll reopen!

@stale stale bot closed this as completed Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants