[
https://issues.apache.org/jira/browse/COLLECTIONS-770?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17528243#comment-17528243
]
Ng Tsz Sum edited comment on COLLECTIONS-770 at 4/26/22 3:27 PM:
-----------------------------------------------------------------
After some test, the problem is the huge number of IteratorChain#hasNext call,
but why the count growth so fast need to further investigate.
||number||hasNext_count||
|1|3|
|2|11|
|3|30|
|4|72|
|5|161|
|6|345|
|7|720|
|8|1478|
|9|3003|
|10|6063|
|11|12194|
|12|24468|
|13|49029|
|14|98165|
|15|196452|
|16|393042|
|17|786239|
|18|1572651|
|19|3145494|
|20|6291200|
|21|12582633|
|22|25165521|
|23|50331320|
|24|100662942|
|25|201326211|
|26|402652775|
|27|805305930|
|28|1610612268|
|29|3221224973|
|30|6442450413|
was (Author: samabcde):
After some test, the problem is the huge number of IteratorChain#hasNext call,
but why the count growth so fast need to further investigate.
[^countHasNextCall.patch]
||number||hasNext_count||
|1|3|
|2|11|
|3|30|
|4|72|
|5|161|
|6|345|
|7|720|
|8|1478|
|9|3003|
|10|6063|
|11|12194|
|12|24468|
|13|49029|
|14|98165|
|15|196452|
|16|393042|
|17|786239|
|18|1572651|
|19|3145494|
|20|6291200|
|21|12582633|
|22|25165521|
|23|50331320|
|24|100662942|
|25|201326211|
|26|402652775|
|27|805305930|
|28|1610612268|
|29|3221224973|
|30|6442450413|
> 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
>
>
> 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.7#820007)