[
https://issues.apache.org/jira/browse/COLLECTIONS-770?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18010464#comment-18010464
]
Joerg Budischewski commented on COLLECTIONS-770:
------------------------------------------------
main problem in Collections-770 is the misuse of the SetUtils.union() function
(as pointed out in Collections-838), as the contract of SetView it is to keep
track of all changes of the mother/father sets, which is not needed for OP's
usecase. So simply replacing the testcode's line
testSet = SetUtils.union(testSet,part);
to
testSet = SetUtils.union(testSet,part).toSet();
thus collapsing each intermediate SetView into a Set fixes OP's problem.
The ChainedIterator is in itself is a problem when chaining mulitiple instances
of itself, my suggestion would be to address that in Collections-722 (though
the idea of the stale PR in 770 of peeking into the UnmodifiableIterator is
really good and should be used).
Improving documentation of SetView and potentially offering an additional
unionSet() method is probably best addressed in Collections-838, so that
Collections-770 could be closed as duplicate to Collections-838.
> ToString method is unresponsive after multiple SetUtils union calls
> -------------------------------------------------------------------
>
> Key: COLLECTIONS-770
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-770
> Project: Commons Collections
> Issue Type: Bug
> Affects Versions: 4.4
> Reporter: Thomas Bürli
> Priority: Minor
> Attachments: SetUtilsTest.java, countHasNextCall.patch, stackdump.txt
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> I had the following code and my application stopped responsing as soon the
> number of names for a userId got too big.
> {code:java}
> Map<String, Set<String>> stringMap = new TreeMap<>();
> for (String name : names) {
> for (String userId : userIds) {
> stringMap.merge(userId, Collections.singleton(name),
> SetUtils::union);
> }
> }
> {code}
> I did some debugging and it occurs when the toString method of one the set is
> called. It looks like the issues is with the iterator of "SetUtils.SetView".
> Here just the method I used to create test sets and in the attachment you
> find the full tests class and a stack dump. The execution time is growing
> exponentially with the numbers of times the SetUtils.union is called. So for
> 29 elements it took 16 seconds to execute toString, and with 30 it took 32
> seconds.
> {code:java}
> @Test
> void setWith20Elements() {
> assertTimeout(ofSeconds(2), () -> createSet(30).toString());
> }
> Set<String> createSet(int number) {
> List<String> inputs = new ArrayList<>();
> for (int i = 0; i < number; i++) {
> inputs.add("Test"+ i);
> }
> Set<String> testSet = Collections.singleton("String1");
> for (String element : inputs) {
> Set<String> part = Collections.singleton(element);
> testSet = SetUtils.union(testSet,part);
> }
> return testSet;
> }
> {code}
> Thanks for your support
--
This message was sent by Atlassian Jira
(v8.20.10#820010)