|
Mr Andersson, Newbie
Posted: 23 February 2012 01:24 PM Total Posts: 16
I’m doing an “upgrade” of a project originally made with Away3D 3.4-ish. Since 3.6 should use native matrix operations and so on, I thought it should be a lot faster, on par with away3d lite.
So after much work getting it running with latest 3.6, it turns out, besides a lot of issues, it is a lot slower than the old compile. I get about half the frame rate…
To investigate I modified the “multi mario”-example for both 3.4 and 3.6 to show 25 marios, and indeed, there the 3.6 version was about twice as fast as the 3.4 (10 fps to 5). But my project is crawling, and I don’t understand why.
A scene with just a skybox, groundplane, and a few simple objects (lit by a single DirectionalLight), no animations (148 meshes, 1677 triangles), gives me a disappointing 7 fps. My old version would be around 13 fps.
Compare that to my 25-mario-version, that runs with about the same fps, but has 14400 triangles (in 52 meshes).
Any ideas?
EDIT: Removing lightning will only kick up the frame rate to 8-10 fps.
|
FLAmaniac, Newbie
Posted: 23 February 2012 02:39 PM Total Posts: 9
[ # 1 ]
Maybe you export debug version not relese?
|
Mr Andersson, Newbie
Posted: 23 February 2012 02:45 PM Total Posts: 16
[ # 2 ]
Nay, unfortunately not. Double and tripple checked
Unless there is subtle things going on, because it sure feels like a debug version…
|
Mr Andersson, Newbie
Posted: 24 February 2012 09:32 AM Total Posts: 16
[ # 3 ]
I would be happy if someone could point out someplace where I can find info about changes from these versions. A lot seems to be different, and colors and lightning looks different, among other things. I’ve tried to study on google code, but it is really hard to get anything out meaningful of that.
|
Mr Andersson, Newbie
Posted: 04 March 2012 02:48 PM Total Posts: 16
[ # 4 ]
Doesn’t seem to be much interest here, but I’ll add my bits anyway.
I’ve upgrading revision by revision, carefully checking the results and fixing as I go along. This performance hit seems to have come with revision 2799, http://code.google.com/p/away3d/source/detail?r=2799 . In most of my test cases, I get about half the frame rate compared to the previous revision. I can note that my scene consists mostly of cloned collada animations
I haven’t yet studied it too closely, and haven’t found the cause, but the description says “first round vectorising arrays”, so could be related to that. I remember seeing some discussion about that, but can’t find it now.
|
Mr Andersson, Newbie
Posted: 04 March 2012 05:23 PM Total Posts: 16
[ # 5 ]
Ok, identified the piece of code that bogs my project down!
In the r2799 version of Object3D, the lookAt() function is rewritten. Using the old version, everything is fine, using the new it crawls to a stop (or about 1/3 the speed). The killer line seems to be
if (Matrix3DUtils.compare(oldTransform, _transform)) return;
If I use the new version of the function, but comment out these lines, it’s almost as fast as before (slightly slower I think though).
By using, I mean replacing the function definition. I don’t really call the function directly anywhere, but apparently it gets called a lot from somewhere; something I shall investigate, because I don’t think it should be called at all during the phases I test with.
I do think that the Matrix3DUtils.compare() function is funny though. Convert both to strings and then compare them seems very expensive to me (creating temporary objects and conversion/comparison possibly involving locale/encoding and so forth).
In this revision, Object3D/set transform() also added this compare-business. When I added that, I think I saw a slight drop in performance as well (but not sure).
Btw, the performance of 2799 is on par to when I tried the latest, and there has been no change to the relevant parts since.
|
Mr Andersson, Newbie
Posted: 04 March 2012 06:07 PM Total Posts: 16
[ # 6 ]
Alright, uncovered some more wierdness.
What is calling lookAt() is TargetCamera3D::viewMatrix():
public override function get viewMatrix():Matrix3D { if (target != null) lookAt(target.scene ? target.scenePosition : target.position); return super.viewMatrix; }
So, that everytime the cameras viewMatrix is accessed, it calls lookAt()! In my test that is almost 1800 times *every frame*, mainly by the ProjectionTraverser. Explains why my code is bogged down, and why the new lookAt() version had such an impact on performance…
I suppose I should find a way so it only calls lookAt() once every rendering session, and/or only if the position of the camera or target has changed. Not sure about the best way to fix that
|
Mr Andersson, Newbie
Posted: 04 March 2012 06:56 PM Total Posts: 16
[ # 7 ]
I made a modification to TargetCamera3D so that lookAt() is only called if camera or target position has changed. Basically:
if (target != null) { var targetPosition:Vector3D = target.scene ? target.scenePosition : target.position; if (!_viewMatrixCameraPos || !_viewMatrixTargetPos || !_viewMatrixCameraPos.equals(position) || !_viewMatrixTargetPos.equals(target.position)) { _viewMatrixCameraPos = position.clone(); _viewMatrixTargetPos = target.position.clone(); lookAt(targetPosition); } } ...
Would be better to use some “dirty” system, but will suffice for now.
However, still quite expensive check though, so I looked into it and saw that it was PrimitiveProjector::project() that read viewMatrix all the time. It updated its own _cameraViewMatrix for every object it projected. I removed that, and instead just did it in the constructor:
public function PrimitiveProjector(view:View3D) { _view = view; _cameraVarsStore = _view.cameraVarsStore; _cameraViewMatrix = _view.camera.viewMatrix; }
Which worked for me with no ill effects, and gave me a speed boost around 10-20%.
|
|
Mr Andersson, Newbie
Posted: 04 March 2012 07:50 PM Total Posts: 16
[ # 9 ]
Well, originally I think it was trunk/fp10 and also tags/3.6.
Now I just incrementally upgrade each revision manually, and i’m on 2799 which is around 3.5.4-ish i think. There i’ve identified the big culprit, as outlined above. I have a bit to go still, but i think i have adressed most of the issues i encountered when first trying to upgrade to latest.
However, I still have hardly any performance increase in sight, which was the whole point of upgrading in the first place… I’m hoping someone might suggest which areas of the engine has had the greatest improvements since back then, and that i’m using parts that’s now obsolete or something.
|