Ticket #2284 (new bug)

Opened 3 months ago

Last modified 1 month ago

Stack-hack optimization causes much re-computation in GUI callbacks

Reported by: sedillard Assigned to:
Priority: normal Milestone: _|_
Component: Compiler Version: 6.8.2
Severity: normal Keywords:
Cc: Difficulty: Unknown
Test Case: Architecture: Unknown
Operating System: Multiple

Description

This is a duplicate of #1168, recorded for posterity here, at the request of Simon PJ,

http://www.haskell.org/pipermail/glasgow-haskell-users/2008-May/014739.html

An IO lambda is created within main's scope, and this is given to the GLUT GUI library (or it could be GTK or wxHaskell) as a callback to draw the contents of the window. The callback lambda captures a value from the outer scope, but the state-hack inlines the value's defining expression into the callback. Thus, the value is re-computed every time the callback is called.

-fno-state-hack fixes it.

The attached program is a 3D model viewer. I've attached two models, one is small, the other larger. The performance hit is quite noticeable on the large one. The models need to be unzipped before running.

gunzip torus.obj.gz
./ObjView torus.obj

use x y z to rotate and force a redraw. When compiled with -O0 or -fno-state-hack, you'll see "BUILDING MESH" output once, otherwise it will be output on every redraw.

Attachments

ObjView.hs (7.9 kB) - added by sedillard on 05/14/08 08:23:51.
torus.obj.gz (3.1 kB) - added by sedillard on 05/14/08 08:24:21.

Change History

05/14/08 08:23:51 changed by sedillard

  • attachment ObjView.hs added.

05/14/08 08:24:21 changed by sedillard

  • attachment torus.obj.gz added.

05/14/08 08:27:37 changed by sedillard

Oops the big test file is too big. You can download it here:

http://graphics.cs.ucdavis.edu/~sdillard/horse.obj.gz

With -O2 and -fno-state-hack it actually does quite well on my 2.1Ghz machine.

Scott

05/15/08 01:46:21 changed by simonpj

  • difficulty set to Unknown.

06/08/08 04:55:22 changed by igloo

  • milestone set to 6.10 branch.

07/11/08 06:28:39 changed by simonmar

  • milestone changed from 6.10 branch to _|_.

_|_, since it's a duplicate of #1168 and we have no short term plans to fix that