Difference between revisions of "Optimization"

From Screeps Wiki
Jump to navigation Jump to search
m (→‎Target Selection: formatting for italicized emphasis)
(Added Figure 1 image)
 
Line 19: Line 19:
 
==== Memory Efficiency ====
 
==== Memory Efficiency ====
 
A subset of CPU efficiency, it's when you trim your memory usage to minimize the parse/serialization CPU usage
 
A subset of CPU efficiency, it's when you trim your memory usage to minimize the parse/serialization CPU usage
  +
[[File:Efficiency Target Triangle (Figure 1).jpg|thumb|Efficiency Target Triangle (Figure 1) - This is a visual representation (with examples) that optimizing towards one efficiency type is typically detrimental to the other two major types.]]
   
 
== Target Selection ==
 
== Target Selection ==

Latest revision as of 17:54, 17 March 2022

Optimization is is the act of making your code more efficient in some form or manner. In order to optimize, a target must be chosen to optimize towards.

Types of Efficiency Targets[edit | edit source]

CPU efficiency[edit | edit source]

Optimizing to use the least amount of CPU to complete a specific task like locking creeps to 1 intent per tick to reduce average CPU usage. See the category CPU Optimization for examples. This is the most familiar target, allowing you to reduce your CPU usage, or do more with the same amount of CPU.

Game Efficiency[edit | edit source]

This is when you target your code to do multiple things at once (e.g. carriers fill an extension and move to the next one on the same tick).

Energy Efficiency[edit | edit source]

When something you do saves energy or maximizes energy input (e.g. calculating and spawning the exact size of carriers needed based on distance of the remote source)

Other Efficiencies[edit | edit source]

Spawn Efficiency[edit | edit source]

When you want to maintain the maximum amount of creeps (or creep parts) out of a single spawn during a single creep cycle (1500 ticks)

Memory Efficiency[edit | edit source]

A subset of CPU efficiency, it's when you trim your memory usage to minimize the parse/serialization CPU usage

Efficiency Target Triangle (Figure 1) - This is a visual representation (with examples) that optimizing towards one efficiency type is typically detrimental to the other two major types.

Target Selection[edit | edit source]

Looking at these types of efficiency, you can see that some implementations targeting one are mutually exclusive of others. You cannot both lock creeps to 1 intent per tick and move and fill extensions on the same tick. This forces us to look at each optimization target (efficiency type) as a scale.

Looking at Figure 1, you can see that each of the targets have a theoretical "perfect" point. The closer you get to any of these, the farther away from the others you get. Every edit to your code is a trade off, just like the traditional CPU vs memory trade off that computer programmers have had since the beginning. You target one, and sacrifice others.

Usefulness of multiple targets[edit | edit source]

Different efficiency targets are beneficial at different points in the game.

Early Game[edit | edit source]

Early, when you only have one room, you will have more CPU than you need. Focusing on Energy efficiency will allow you to upgrade your Controller faster, to increase your RCL and GCL.

Mid-Game[edit | edit source]

Mid-Game, You're a little more established and are less concerned solely about energy, and will want to increase and expand your operations, so game efficiency is a more logical target during this period. You're still not doing too much, so CPU is not yet an issue, so it does not need to be the sole target yet.

Late Game[edit | edit source]

Late Game is very CPU constrained. A large player with 50+ rooms of vision per-tick (typical of even RCL 20 players) will have a lot of logistics, intelligence, trading code, and more all vying for CPU usage. Operating Systems become more appealing in an attempt to manage the CPU. At this point, CPU efficiency becomes the only reasonable target, and you will need to focus solely on that.