[m-dev.] Performance of collect

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Sep 24 00:36:54 AEDT 2000


On 22-Sep-2000, Erwan Jahier <Erwan.Jahier at irisa.fr> wrote:
> I am still in the process to understand why collect(nop, _) (where nop define 
> a monitor that does nothing) is so slow.
> 
> Currently, with 11-queens (34 000 000 events) the timings are:
> 
> off line, no trace info: ~4s
> mdb ./queens11 < finish: ~20s
> collect(nop, Result)   : ~200s (now) 
> collect(nop, Result)   : ~800s (before I move MR_COLLECT_filter to MR_trace_real()) 

On what architecture?
In what grade?

> If I remove the call to filter in mercury_trace_external: 80s
>  
> If I remove the call to filter in mercury_trace_external
> *AND* I remove the save_regs/restore regs statements    : 20s
> 
> So the save_regs/restore regs statements seems to cost me 40s, and the call to
> *filter_ptr() (which does nothing with nop monitor) seems to cost 120s.
> 
> Why is this call so expensive? 

You're calling from C to Mercury.  In our current implementation (LLDS back-end),
this is fairly expensive.  The generated code for `pragma export' functions
typically looks like this:

	void
	write_str(MR_String Mercury__argument1)
	{
	#if NUM_REAL_REGS > 0
		MR_Word c_regs[NUM_REAL_REGS];
	#endif

		save_regs_to_mem(c_regs);
	#if MR_THREAD_SAFE
		init_thread(MR_use_now);
	#endif
		restore_registers();
		r1 = (MR_Word) Mercury__argument1;
		save_transient_registers();
		(void) MR_call_engine(ENTRY(mercury__io__write_string_3_0), FALSE);
		restore_transient_registers();
		restore_regs_from_mem(c_regs);
	}

See the comments in export.m for why each of these lines is needed.
Then there's also quite a bit of work done in MR_call_engine(),
e.g. it calls setjmp(), and then longjmp() to return.

Some of this, e.g. the calls to save_regs_to_mem(c_regs) and
restore_regs_from_mem(c_regs), are not necessarily in this particular
case, since the C code that you're calling from all includes the
Mercury header files with the Mecury global register variable
declarations.  But it is needed for `pragma export' in general.
I suppose you could define a variant of `pragma export' specifically
for this purpose which avoided some of the overhead, although I'm
not sure whether that would really be worth the effort.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list