eclipse-collections icon indicating copy to clipboard operation
eclipse-collections copied to clipboard

Optimize withAll on MutableIntSetFactoryImpl and ImmutableIntSetFactoryImpl

Open donraab opened this issue 3 years ago • 4 comments

The code currently in withAll on both mutable and immutable implementations calls toArray on IntStream which if the Stream is very large can be extremely expensive and won't take advantage of a Set's ability to store only unique elements.

Current mutable factory code:

public MutableIntSet withAll(IntStream items)
{
    return this.with(items.toArray());
}

Current immutable factory code:

public ImmutableIntSet withAll(IntStream items)
{
    return this.with(items.toArray());
}

donraab avatar Aug 14 '22 02:08 donraab

Hey @donraab How can I help here? Can you please explain to me a bit more about this because I am new to the eclipse collection

gaurangkudale avatar Aug 20 '22 07:08 gaurangkudale

Hi @gaurangkudale, thank you for the questions and your interest in Eclipse Collections! I always recommend starting by working through the Eclipse Collections Katas to understand the library if you haven't used it before.

https://github.com/eclipse/eclipse-collections-kata

You'll probably have gotten an idea of how things work after the Pet Kata and that may be enough to get started. The other katas will continue to build up new or reinforce existing knowledge about the library.

I can this assign the issue to you if you are interested in working on this. There is also a great blog about making a first contribution to Eclipse Collections from a first time contributor.

https://mydeveloperplanet.com/2021/01/20/how-to-start-contributing-to-open-source/

Hope this helps.

donraab avatar Aug 20 '22 21:08 donraab

Hi @donraab Thans for information I'd like to work on this issue

gaurangkudale avatar Aug 21 '22 02:08 gaurangkudale

Thanks for volunteering @gaurangkudale! I've assigned the issue to you.

donraab avatar Aug 21 '22 05:08 donraab

@donraab hey - what optimization did you have in mind here? trying to do a distinct on the stream perhaps or

Desislav-Petrov avatar Mar 18 '23 22:03 Desislav-Petrov

Just add the elements directly from the IntStream to a MutableIntSet. In the ImmutableIntSet case, create a MutableIntSet from the IntStream and call toImmutable() at the end.

donraab avatar Mar 18 '23 23:03 donraab