Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#3541 closed enhancement (fixed)

[PATCH] Optimize TestRayAASquare in Geometry.cpp

Reported by: Stan Owned by: Stan
Priority: Nice to Have Milestone: Alpha 20
Component: Core engine Keywords: patch
Cc: Patch:

Description

There is a todo line 244 of Geometry.cpp that says :

// Exactly like TestRaySquare with u=(1,0), v=(0,1)
// Assume the compiler is clever enough to inline and simplify all this
// (TODO: stop assuming that)

Attachments (8)

3451.diff (1.8 KB ) - added by Stan 8 years ago.
Fix the Todo.
3451.1.diff (2.0 KB ) - added by Stan 8 years ago.
Documented Version of Above Patch
3451.2.diff (2.6 KB ) - added by Stan 8 years ago.
Replace some scalar computations by the value to save some computations, add doxygen documentation, and rename some variables to make the code more readable.
3451.3.diff (2.2 KB ) - added by Stan 8 years ago.
Assert the previous comments, though we cannot remove u and v for now.
3451.4.diff (3.0 KB ) - added by Stan 8 years ago.
A proposal to simplify further the code.
t3451_optimize_TestRayAASquare_v4.patch (2.5 KB ) - added by elexis 8 years ago.
profile.7z (405.5 KB ) - added by elexis 8 years ago.
An alpha 19 replay and it's profiling data showing the performance details. The match was a 40min 3v3 with 200 pop capacity and too many trees.
profile.jpg (80.8 KB ) - added by elexis 8 years ago.

Download all attachments as: .zip

Change History (14)

by Stan, 8 years ago

Attachment: 3451.diff added

Fix the Todo.

comment:1 by Stan, 8 years ago

Owner: set to Stan
Status: newassigned

by Stan, 8 years ago

Attachment: 3451.1.diff added

Documented Version of Above Patch

by Stan, 8 years ago

Attachment: 3451.2.diff added

Replace some scalar computations by the value to save some computations, add doxygen documentation, and rename some variables to make the code more readable.

comment:2 by elexis, 8 years ago

Keywords: pathfinding added
Summary: [PATCH] Remove Redundant Code in geometry.cpp[PATCH] Optimize TestRayAASquare in Geometry.cpp

Yeah, that's the right direction in my understanding.

  • It would be better though to not rename variables, as they have the same name in the other code as well and the patch will be easier to review.
  • Remove the au, av, bu, bv variables, as you can just reference u.X etc..
  • The goal is to completely remove the constants u, v. So the u.Multiply(hw) things also need to be simplified / consolidated.

Those vector functions are defined in FixedVector2D.h and reflect the usual vector operations known from linear algebra.

by Stan, 8 years ago

Attachment: 3451.3.diff added

Assert the previous comments, though we cannot remove u and v for now.

comment:3 by Stan, 8 years ago

Here are the maths behind the changes as you can see there is not much to be done for s1,s3 as you cannot simply inver halfsize.X in one line same for halfsize.Y we could add an MultiplyCoordinate in CFixedVector2D function which would basically return (X*n,Y*m) that would fix it.

S0
(1;0) * X + (0;1) * Y - (B;C)
= (X;Y) - (B;C)
= (X-B;Y-C)
= (Halfsize - a)

S1
(1;0) * X - (0;1) * Y - (B;C)
= (X; - Y) - (B;C)
= (X-B;-Y-C)

S2
- (1;0) * X - (0;1) * Y - (B;C)
= -(X;Y) - (B;C)
= (-X-B;-Y-C)
= (-Halfsize - a)

S3
- (1;0) * X + (0;1) * Y - (B;C)
= (-X;Y) - (B;C)
= (-X-B;Y-C)
Last edited 8 years ago by Stan (previous) (diff)

by Stan, 8 years ago

Attachment: 3451.4.diff added

A proposal to simplify further the code.

comment:4 by elexis, 8 years ago

Milestone: BacklogAlpha 20
Priority: Should HaveNice to Have

by elexis, 8 years ago

Attachment: profile.7z added

An alpha 19 replay and it's profiling data showing the performance details. The match was a 40min 3v3 with 200 pop capacity and too many trees.

by elexis, 8 years ago

Attachment: profile.jpg added

comment:5 by elexis, 8 years ago

Resolution: fixed
Status: assignedclosed

In 17500:

Pathfinder optimization, fixes #3541.
Simplify the math of Geometry::TestRayAASquare.

comment:6 by elexis, 8 years ago

Cc: Itms removed
Keywords: pathfinding review removed
Type: defectenhancement

http://trac.wildfiregames.com/raw-attachment/ticket/3541/profile.jpg

The patch removes two constants (0 and 1) and useless compuation (for example 1*x + 0*y).

Notice the last two peaks show 10% performance improvement. Otherwise not too much gain.

Note: See TracTickets for help on using tickets.