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

perf: handle some concurrency in ModelSet #3736

Merged
merged 1 commit into from
Dec 22, 2020

Conversation

sibwaf
Copy link
Contributor

@sibwaf sibwaf commented Dec 21, 2020

Reading the model sometimes leads to it's modification: for example, CtTypeReferenceImpl.getTypeDeclaration() may start building a shadow type which is then added to the model. This causes modification of the types ModelSet in CtPackageImpl, which is backed by a TreeSet (which is in turn backed by a TreeMap). Thus a TreeMap can be modified concurrently when multiple threads try to get a type declaration (or an executable declaration), which sometimes causes an infinite loop.

This fix is mostly "treating the symptoms" and it doesn't provide sufficient synchronization across the library so ConcurrentModificationException is still possible, but it at least prevents the infinite loop.

This fix doesn't seem to have too much impact on performance (at least in the "real-world scenario" of building the model by a Launcher and then reading it by multiple threads).

@monperrus monperrus changed the title review: fix: Prevent state corruption in ModelSet when it's concurrently modified perf: handle some concurrency in ModelSet Dec 22, 2020
@monperrus monperrus merged commit 3435fac into INRIA:master Dec 22, 2020
@monperrus
Copy link
Collaborator

Nice, we very much value performance and concurrency PRs in Spoon!

@sibwaf sibwaf deleted the FixInfiniteLoopInModelSet branch December 22, 2020 15:41
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.

2 participants