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

Bug in deleteAll in Maps #1701

Closed
hiranpodi opened this issue Mar 29, 2019 · 2 comments
Closed

Bug in deleteAll in Maps #1701

hiranpodi opened this issue Mar 29, 2019 · 2 comments
Labels
Milestone

Comments

@hiranpodi
Copy link

hiranpodi commented Mar 29, 2019

This issue is with Maps have 15 or more elements,

How to reproduce:

  1. Create a immutable Map with 15 elements. e.g.

( {a: 'aaaa', b: 'bbbb'...... p: 'pppp'})

  1. Add two of the Keys to an array.
    e.g

. [ 'a', 'b']

  1. Use "deleteAll" to delete elements with keys selected in step 2.
    e.g

map1.deleteAll([ 'a', 'b'])

  1. Add two new elements to the Map.
    e.g.

map1.set('x','xxx');
map1.set('y','yyy');

  1. Repeat step "2" to "4" , 15 times. on the 16th deletion the two elements will not be deleted from the Map.

A working example of this issue can be found in this link:

http://jsfiddle.net/n8e9ufgc/4

Version : 4.0.0.-rc.12

image

@acusti
Copy link
Contributor

acusti commented Sep 16, 2019

i reproduced this and have a few additional findings:

  1. it only applies to OrderedMap, not Map: fiddle with OrderedMap, fiddle with Map
  2. only a single new item needs to be set and a single old item removed via deleteAll to trigger the bug
  3. the point at which the deleteAll calls start failing varies depending on the size of the OrderedMap and on how many items are being added and deleted. having an OrderedMap of size 15 will fail quickest (after 18 iterations), while a size of 14 and a size of 16 will take 19 iterations. try this in the browser console at https://immutable-js.github.io/immutable-js/docs/ to see that happen, then try tweaking the top config options:
var collectionSize = 15;
var totalIterations = 18;

var map = Immutable.OrderedMap();
var clickCount = 0;
for (var i = 0; i < collectionSize - 1; i++) { 
  map = map.set(i, {a: i})
}

var previousIndex = collectionSize - 1;
var index;

for (var i = 0; i < totalIterations; i++) {
  // First, add a new item
  index = Math.random() * 100;
  map = map.set(index, {a: index});
  // Then delete the previously added item
  map = map.deleteAll([previousIndex]);
  // Update previousIndex for next iteration
  previousIndex = index;
}
map;

by the end of the above code snippet, map.size will be 16 when it should be 15. if you run the same thing but have the second loop execute one less iteration (totalIterations = 17), the bug will not exhibit and map.size will be 15.

the amount of time it takes to trigger the bug seems to remain symmetrical from the distance away from size 15. when collectionSize = 1, it takes 32 iterations, which is the same for collectionSize = 29.

@jdeniau
Copy link
Member

jdeniau commented Jul 9, 2021

Hi,

This has been fixed in the latest rc 4.0.0-rc.14

Thank you for your patience !

@jdeniau jdeniau closed this as completed Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants