Opened 6 years ago

Closed 2 years ago

#7960 closed bug (fixed)

Compiling profiling CCS registration .c file takes far too long

Reported by: duncan Owned by:
Priority: normal Milestone: 8.4.1
Component: Compiler Version: 7.6.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


When compiling executables for profiling, ghc generates a .c file something like this:

#define IN_STG_CODE 0
#include "Rts.h"
#include "Stg.h"
static void prof_init_Main(void) __attribute__((constructor));
static void prof_init_Main(void)
{extern CostCentre Foo_bar_cc[];

When there are a large number of CCSs, e.g. 10's of 1,000s (as can easily happen with large projects and using -fprof-auto) then of course this .c file and this single C function become very large. The C compiler then takes a very long time to compile it.

For example, with a .c file with ~27k lines (so about half that number of CCSs), gcc 4.7.2 with -O1 takes about 20 minutes to compile. With -O0 it takes about 4 seconds. Clearly this version of gcc does not cope very well with this massive function at -O1 level.

I suggest that since the initialisation is not performance critical, and it doesn't look like there is a lot to optimise here anyway, that ghc compile this .c file without passing gcc the -O flag.

Change History (3)

comment:1 Changed 6 years ago by simonpj

difficulty: Unknown

OK with me. Offer a patch?

comment:2 Changed 2 years ago by Ben Gamari <ben@…>

In a8da0de2/ghc:

Speed up compilation of profiling stubs

Here we encode the cost centre list as static data. This means that the
initialization stubs are small functions which should be easy for GCC to
compile, even with optimization.

Fixes #7960.

Test Plan: Test profiling

Reviewers: austin, erikd, simonmar

Reviewed By: simonmar

Subscribers: rwbarton, thomie

GHC Trac Issues: #7960

Differential Revision:

comment:3 Changed 2 years ago by bgamari

Milestone: 8.4.1
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.