id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	os	architecture	failure	difficulty	testcase	blockedby	blocking	related
2284	Stack-hack optimization causes much re-computation in GUI callbacks	sedillard		"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.
 "	bug	closed	normal	_|_	Compiler	6.8.2	duplicate		JulesBean	Unknown/Multiple	Unknown/Multiple	None/Unknown	Unknown				
