[PR 453] aggressiv cache for _get_design_by_name (AI)

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
banduri
Space Floater
Posts: 47
Joined: Tue Dec 15, 2015 6:20 pm
Location: Solaria

[PR 453] aggressiv cache for _get_design_by_name (AI)

#1 Post by banduri » Fri Jan 22, 2016 5:33 pm

I had some fun with the AI. Did some profiling to figure out which part of the AI is slow. I think the _get_design_by_name in ShipDesignAI could be a little bit faster, if invalid designs are also cached. The Pullrequest https://github.com/freeorion/freeorion/pull/453 does that. It stores invalid designs in cache to increase cache hits. After a new design is created via issueCreateShipDesignOrder the cache gets updated. At the begining of each turn, durring the cache_consistency_check, invalid ship designs are removed from the cache.

I did some testing with a single AI and looked at the timers but I'm not sure about the changes since I'm not that familiar with the overall design of the AI. I would like to know whether I did something really bad :)

edit: removed quote-tags
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project (this includes pullrequest of the useraccount banduri at github)

Morlic
AI Contributor
Posts: 238
Joined: Tue Feb 17, 2015 11:54 am

Re: [PR 453] aggressiv cache for _get_design_by_name (AI)

#2 Post by Morlic » Fri Jan 22, 2016 8:05 pm

That seems like a good approach overall (for code discussion, see PR). Do you have any numbers concerning how often the cache was missed (There is some profiling information for ShipDesignAI included in the AI logs).
I did some testing with a single AI and looked at the timers but I'm not sure about the changes since I'm not that familiar with the overall design of the AI. I would like to know whether I did something really bad :)
If you break the AI, you will notice it by ingame error chat messages and/or by errors in the logs. So if you do something "really bad" you will usually know.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

banduri
Space Floater
Posts: 47
Joined: Tue Dec 15, 2015 6:20 pm
Location: Solaria

Re: [PR 453] aggressiv cache for _get_design_by_name (AI)

#3 Post by banduri » Fri Jan 22, 2016 9:40 pm

Morlic wrote:That seems like a good approach overall (for code discussion, see PR). Do you have any numbers concerning how often the cache was missed (There is some profiling information for ShipDesignAI included in the AI logs).
to generate the timing graphs I did something like this:
enable timers:

Code: Select all

cat <<EOF >> default/AI/default_config.ini
[Timers]
timers_to_log = True
timers_dump = True
timers_dump_folder = /tmp/timers/

[main]
handlers = 

EOF
call freeorion in a loop to create data

Code: Select all

mkdir /tmp/timers /tmp/data; for i in $(seq 0 9);do ./freeorion -q -r  --GameSetup.ai-players 1 --max-fps 15 --max-fps-no_focus 15 --auto-advance-n-turns 400 --auto-quit; cp ~/.freeorion/*.log /tmp/timers; mv /tmp/timers /tmp/data/timers_${i}; mkdir /tmp/timers;done
the vistime.py.log attachment created the images for the two different runs with and without the PR
without_patch.png
without_patch.png (93.64 KiB) Viewed 627 times
with_patch.png
with_patch.png (123.16 KiB) Viewed 627 times
Morlic wrote:If you break the AI, you will notice it by ingame error chat messages and/or by errors in the logs. So if you do something "really bad" you will usually know.
About that: from time to time i get:

Code: Select all

[debug] AI : Chat Message to human: AI_Error: AI script error in "survey_universe": "'NoneType' object has no attribute 'tags'"
[debug] AI : 
[error] AI : PythonLoggingWrapper.cpp:41 : Traceback (most recent call last):
[error] AI : PythonLoggingWrapper.cpp:41 :   File "/home/asklepios/GITs/freeorion_build/default/AI/FreeOrionAI.py", line 239, in generateOrders
[error] AI : PythonLoggingWrapper.cpp:41 :     action()
[error] AI : PythonLoggingWrapper.cpp:41 :   File "/home/asklepios/GITs/freeorion_build/default/AI/ColonisationAI.py", line 421, in survey_universe
[error] AI : PythonLoggingWrapper.cpp:41 :     for metab in [tag for tag in this_spec.tags if tag in AIDependencies.metabolismBoostMap]:
[error] AI : PythonLoggingWrapper.cpp:41 : AttributeError: 'NoneType' object has no attribute 'tags'
Any clue/hints on that?

edit: missing closing qute
Attachments
vistime.py.log
pythoncode - remove ".log" extension
(1.56 KiB) Downloaded 30 times
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project (this includes pullrequest of the useraccount banduri at github)

User avatar
Cjkjvfnby
AI Contributor
Posts: 448
Joined: Tue Jun 24, 2014 9:55 pm

Re: [PR 453] aggressiv cache for _get_design_by_name (AI)

#4 Post by Cjkjvfnby » Sat Jan 23, 2016 9:25 am

banduri wrote: to generate the timing graphs I did something like this:
You can create config in separate file and run it with `--ai-config <path>`
Any clue/hints on that?
Looks like wired bug. Do you have log for this case?

May be planet destroyed but it is still return owner and population?

PS. You can share python files via https://gist.github.com/
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Post Reply