Skip to content

Avoid inefficient usage of arraylist#92

Closed
FastAtlas wants to merge 3 commits into
apache:masterfrom
FastAtlas:master
Closed

Avoid inefficient usage of arraylist#92
FastAtlas wants to merge 3 commits into
apache:masterfrom
FastAtlas:master

Conversation

@FastAtlas

Copy link
Copy Markdown

Hi,
We find that there are three ArrayList objects which are not manipulated by random access. Due to the memory reallocation triggered in the successive insertions, the time complexity of add method of ArrayList is amortized O(1). We notice that these objects are only used for traversal and the retrieval for the first or the last element.

This functionality can be implemented by LinkedList. Moreover, the insertion of LinkedList is strictly O(1) time complexity because no memory reallocation occurs.

We discovered this inefficient usage of containers by our tool Ditto. The patch is submitted. Could you please check and accept it? We have tested the patch on our PC. The patched program works well.

Bests

Ditto

@coveralls

coveralls commented Sep 4, 2021

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 94.682% when pulling e1eff30 on DittoTool:master into fd44e6b on apache:master.

@jochenw

jochenw commented Sep 14, 2021

Copy link
Copy Markdown
Contributor

Are there any sources, that you can quote with regards to the complexity of ArrayList vs. LinkedList? Thanks, Jochen

@jochenw

jochenw commented Sep 14, 2021

Copy link
Copy Markdown
Contributor

Besides: What is the tool Ditto, that you are referring to?

@garydgregory

Copy link
Copy Markdown
Member

I do not think we should change internals until we have an example that demonstrates whatever problem this tool thinks it found. This feels backward to me because accessing the first and/last element of an array is fast and an array list grows in chunks.

@garydgregory

Copy link
Copy Markdown
Member

Tree maps are also handy for reproducing the same result over and over, also needs a demonstration of what the problem is in pragmatic terms.

@jochenw

jochenw commented Sep 14, 2021

Copy link
Copy Markdown
Contributor

I do not think we should change internals until we have an example that demonstrates whatever problem this tool thinks it found. This feels backward to me because accessing the first and/last element of an array is fast and an array list grows in chunks.

I think exactly the same, which is why was asking for more infos.

@garydgregory

Copy link
Copy Markdown
Member

Closing, no reply from OP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants