Opened 6 years ago

Closed 15 months ago

#2284 closed bug (duplicate)

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

Reported by: sedillard Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.8.2
Keywords: Cc: JulesBean
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

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 (3)

ObjView.hs (7.9 KB) - added by sedillard 6 years ago.
torus.obj.gz (3.1 KB) - added by sedillard 6 years ago.
boggle.hs (3.1 KB) - added by guest 22 months ago.
an example without GUI dependencies

Download all attachments as: .zip

Change History (12)

Changed 6 years ago by sedillard

Changed 6 years ago by sedillard

comment:1 Changed 6 years ago 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

comment:2 Changed 6 years ago by simonpj

  • Difficulty set to Unknown

comment:3 Changed 6 years ago by igloo

  • Milestone set to 6.10 branch

comment:4 Changed 6 years ago 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

comment:5 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:6 Changed 6 years ago by simonmar

  • Operating System changed from Multiple to Unknown/Multiple

comment:7 Changed 5 years ago by JulesBean

  • Cc JulesBean added

I have a duplicate of this bug. I have code which does something like:

params <- actionToGetParams
let structure = veryExpensivePureOperation params

displayCallback $= (display structure)

and it is easily observed that structure is being recomputed every time the callback is called.

In fact, -fno-state-hack speeds up my program from 110fps to 400fps, a substantial improvement.

Count this as a vote for a solution to this bug...

Changed 22 months ago by guest

an example without GUI dependencies

comment:8 Changed 15 months ago by morabbin

  • Type of failure set to None/Unknown

Claimed as dup of #1168 above, ought to be marked as such? Or vice versa.

comment:9 Changed 15 months ago by simonmar

  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.