Bug 28974 - Extremely slow compilation of enumerated DATA statements.
Summary: Extremely slow compilation of enumerated DATA statements.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Bud Davis
URL:
Keywords: compile-time-hog
Depends on:
Blocks:
 
Reported: 2006-09-07 14:58 UTC by Daniel Franke
Modified: 2006-11-25 04:12 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2006-09-15 02:59:54


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Franke 2006-09-07 14:58:59 UTC
Compilation of enumerated DATA statements is extremely slow. 
Related PR: 
 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13465
Related threads on ML: 
 * http://gcc.gnu.org/ml/fortran/2004-08/msg00131.html
 * http://gcc.gnu.org/ml/fortran/2006-09/msg00025.html

Shell script to generate example data:
$> cat datagen.sh
#! /bin/bash
outfile=data.f90
dim1=50
dim2=1000
echo "MODULE appdata"                              >  ${outfile}
echo "INTEGER :: thedata(${dim1}, ${dim2})"        >> ${outfile}
for i in `seq 1 ${dim1}` ; do
  for j in `seq 1 ${dim2}` ; do
    echo "DATA thedata(${i}, ${j}) / $((i*j)) /"   >> ${outfile}
  done
done
echo "END MODULE"                                  >> ${outfile}

P4 3.2 GHz, 2GB RAM:
$> bash datagen.sh
$> time gfortran-4.2 -c data.f90
real    3m31.646s
user    3m29.545s
sys     0m0.172s
Comment 1 Steven Bosscher 2006-09-07 17:36:45 UTC
Quadratic (or worse?) behavior
Comment 2 Bud Davis 2006-09-15 03:01:49 UTC
This problem is very intriguing.  For a first attempt I plan on adding a splay tree to constructors that need 'by element' access.  This may allow this problem to be taken care of without changing every routine that uses gfc_constructor.

bd
Comment 3 Bud Davis 2006-09-16 15:00:59 UTC
more mailing list traffic on this topic:

http://gcc.gnu.org/ml/fortran/2006-09/msg00210.html


--bud
Comment 4 Bud Davis 2006-09-17 13:54:36 UTC
before the patch:
$ time /usr/local/bin/gfortran -c data.f90

real    3m1.263s
user    3m0.519s
sys     0m0.120s

after:
$ time /usr/local/bin/gfortran -c data.f90

real    0m3.215s
user    0m3.052s
sys     0m0.092s
Comment 5 Bud Davis 2006-11-06 04:10:16 UTC
patch here:

http://gcc.gnu.org/ml/fortran/2006-11/msg00148.html
Comment 6 Bud Davis 2006-11-15 05:10:32 UTC
Subject: Bug 28974

Author: bdavis
Date: Wed Nov 15 05:10:22 2006
New Revision: 118844

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=118844
Log:
2006-11-15  Bud Davis <bdavis9659@sbcglobal.net>

        PR fortran/28974
        * gfortran.h (gfc_expr): Add element which holds a splay-tree
        for the exclusive purpose of quick access to a constructor by
        offset.
        * data.c (find_con_by_offset): Use the splay tree for the search.
        (gfc_assign_data_value): Use the splay tree.
        (gfc_assign_data_value_range): ditto.
        * expr.c (gfc_get_expr): Initialize new element to null.
        (gfc_free_expr): Delete splay tree when deleting gfc_expr.



Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/data.c
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/gfortran.h

Comment 7 Andrew Pinski 2006-11-25 02:38:56 UTC
Fixed.
Comment 8 Jack Howarth 2006-11-25 04:12:12 UTC
Are there any plans to backport this fix to the gcc 4.2 branch since it does fix a pretty nasty performace hit?