-
Notifications
You must be signed in to change notification settings - Fork 571
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
AI Attack & getSpellAbilityToPlay Timeout #6577
base: master
Are you sure you want to change the base?
Conversation
@kevlahnota about the AI timeout part, how about separating it into extra Threads per creature? threadSafeIterable would that change make problems for this ConcurrentModificationException? When Touching FCollection, how about looking at #3397 ? |
I changed the FCollection LinkedList to Lists.newCopyOnWriteArrayList() so it's already thread safe, threadSafeIterable returns the list directly from FCollection, also it uses Sets.newConcurrentHashSet(), (I think this is a shortcut to ConcurrentHashmap.newkeyset). |
I agree with @tool4ever's observations, and after these tweaks it looks like a very useful and nice option! :) |
I just thought we could clean up some code if we make: less own code means less errors ;P |
Isn't that going to be a massive hit to performance for a lot of the single-threaded code? |
I did profile it and seems ok so far. I don't know any concurrent list that is available. How does the change react to your machine when using it with lots of token/card generation? |
@Hanmac I encountered concurrent modification on Card.class for the Iterable getchangedcardtypes. Is it safe to return ImmutableList.copyOf instead of Iterables.unmodifiableIterable? |
I saw the error too on sentry but I can't explain it yet Do you got a case to reproduce that? If yes I could make a short hot fix |
Replace copyonwritearray to a custom implementation for concurrent modification exception. A little bit slower but supports iterator operations. Added FCollectionTest
I replaced the copyonwritearraylist, I think it's slower but its a good tradeoff for those using iterator functions |
Seems like a worthy trade-off. Performance is important but I think full support for the collection interface is more important for an implementation this widely used. |
move custom multimap implementation for floating mana since this only covers small section
update ManaPoolTest
@Hanmac @Agetian @tool4ever is there any changes needed? FCollection and ManaPool shouldn't throw ConcurrentModification anymore and seems to work fine. |
Well my main concern isn't really addressed: Also the "dumb check" you had to add clearly hints that something with your custom data alternative doesn't fully work and will break some existing AI behaviour. |
Ok I'll revert the Manapool and implement a lock similar to what I did to FCollection and remove the dumb check and restore the sort above it (I still think that's is the cause the of the issue) to satisfy your concern. |
remove ManaPoolTest for concurrency refactor timeout for chooseSpellAbilityToPlayFromList
👍 |
@@ -43,12 +44,40 @@ public static <T> FCollection<T> getEmpty() { | |||
/** | |||
* The {@link Set} representation of this collection. | |||
*/ | |||
private final Set<T> set = Sets.newHashSet(); | |||
private Set<T> SET; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question, why don't you use the default value anymore? I mean there shouldn't be a time where the set/list is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everytime a new cardcollection is created and isn't used because of invalid condition saves a bit of memory. On my local copy when i profile it (Card, player, spellability, etc), unused vars and not initialized if not needed produce good results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that the result of a bunch of fields using them as the default value? Like these in Card.java
?
private List<GameCommand> leavePlayCommandList = Lists.newArrayList();
private final List<GameCommand> untapCommandList = Lists.newArrayList();
private final List<GameCommand> changeControllerCommandList = Lists.newArrayList();
private final List<GameCommand> unattachCommandList = Lists.newArrayList();
private final List<GameCommand> faceupCommandList = Lists.newArrayList();
private final List<GameCommand> facedownCommandList = Lists.newArrayList();
private final List<GameCommand> phaseOutCommandList = Lists.newArrayList();
private final List<Object[]> staticCommandList = Lists.newArrayList();
Might be a good idea in the future to give the same lazy-init treatment to other commonly used classes.
No description provided.