Excessive compilation time

I have a problem with excessive compilation time. The problem is with code automatically translated from another system (gap3) so I cannot easily change it. As an example, the function below takes 2 minutes to compile; as you can see, the code is long but very simple. When you load the code, executing @time f(4) the first time takes 128sec (and some microseconds after that). The following should be noted:

  • If I move the definition of d outside the function the compilation takes a fraction of a second. I can move d out here but not on some other examples where the data defines polynomials that the function evaluates at its argument.

  • If I define the function by function f(x) instead of f=function(x) the time by my stopwatch is the same but @time does not show most of it.

f=function(x)
  d=Dict{Int,Vector{Vector{Int}}}(
  4=>[[1,0],[1,4],[1,8],[1,5,1,7],[1,3,1,5],[1,1,1,3],[1,2,1,4,1,6]],
  5=>[[1,0],[1,4],[1,8],[1,4],[1,8],[1,12],[1,8],[1,12],[1,16],[1,9,1,15],
      [1,7,1,13],[1,5,1,11],[1,7,1,13],[1,5,1,11],[1,3,1,9],[1,5,1,11],
      [1,3,1,9],[1,1,1,7],[1,4,2,10],[1,2,1,8,1,14],[2,6,1,12]],
  6=>[[1,0],[1,4],[1,8],[1,6],[1,10],[1,14],[1,5,1,13],[1,3,1,11],[1,3,1,7],
      [1,7,1,11],[1,1,1,9],[1,5,1,9],[1,2,1,6,1,10],[1,4,1,8,1,12]],
  7=>[[1,0],[1,4],[1,8],[1,4],[1,8],[1,12],[1,8],[1,12],[1,16],[1,6],[1,10],
      [1,14],[1,10],[1,14],[1,18],[1,14],[1,18],[1,22],[1,9,1,21],[1,7,1,19],
      [2,11],[1,7,1,19],[2,11],[2,9],[2,11],[2,9],[2,7],[2,15],[2,13],
      [1,5,1,17],[2,13],[1,5,1,17],[1,3,1,15],[1,5,1,17],[1,3,1,15],[1,1,1,13],
      [3,10],[1,4,2,16],[1,2,2,14],[2,8,1,20],[2,6,1,18],[3,12]],
  8=>[[1,0],[1,6],[1,12],[1,18],[1,1,1,5],[1,4,1,8],[1,7,1,11],[1,7,1,11],
      [1,10,1,14],[1,13,1,17],[1,8,1,12,1,16],[1,6,1,10,1,14],[1,4,1,8,1,12],
      [1,2,1,6,1,10],[1,5,2,9,1,13],[1,3,1,7,1,11,1,15]],
  9=>[[1,0],[1,6],[1,12],[1,18],[1,12],[1,18],[1,24],[1,30],[1,5,1,13],
      [1,4,1,20],[1,7,1,23],[1,7,1,23],[1,10,1,26],[1,13,1,29],[1,1,1,17],
      [1,14,1,22],[1,17,1,25],[1,11,1,19],[1,11,1,19],[1,8,1,16],
      [1,8,1,16,1,24],[1,6,1,14,1,22],[1,4,1,12,1,20],[1,2,1,10,1,18],
      [1,12,1,20,1,28],[1,10,1,18,1,26],[1,8,1,16,1,24],[1,6,1,14,1,22],
      [2,9,1,17,1,25],[1,7,2,15,1,23],[1,3,1,11,1,19,1,27],[1,5,1,13,2,21]],
 10=>[[1,0],[1,6],[1,12],[1,18],[1,8],[1,14],[1,20],[1,26],[1,16],[1,22],
      [1,28],[1,34],[1,9,1,21],[1,12,1,24],[1,15,1,27],[1,15,1,27],
      [1,18,1,30],[1,21,1,33],[1,5,1,17],[1,8,1,20],[1,11,1,23],[1,11,1,23],
      [1,14,1,26],[1,17,1,29],[1,1,1,13],[1,4,1,16],[1,7,1,19],[1,7,1,19],
      [1,10,1,22],[1,13,1,25],[1,8,1,20,1,32],[2,14,1,26],[1,8,2,20],
      [1,2,1,14,1,26],[2,16,1,28],[1,10,2,22],[1,4,1,16,1,28],[2,10,1,22],
      [1,12,2,24],[1,6,1,18,1,30],[2,12,1,24],[1,6,2,18],[2,9,2,21],
      [2,11,2,23],[1,7,2,19,1,31],[1,3,2,15,1,27],[1,5,2,17,1,29],[2,13,2,25]],
 11=>[[1,0],[1,6],[1,12],[1,18],[1,8],[1,14],[1,20],[1,26],[1,16],[1,22],
      [1,28],[1,34],[1,12],[1,18],[1,24],[1,30],[1,20],[1,26],[1,32],[1,38],
      [1,28],[1,34],[1,40],[1,46],[1,9,1,33],[1,12,1,36],[2,27],[2,27],
      [1,18,1,42],[2,33],[1,5,1,29],[2,20],[1,11,1,35],[1,11,1,35],[1,14,1,38],
      [2,29],[1,1,1,25],[1,4,1,28],[1,7,1,31],[1,7,1,31],[2,22],[2,25],[2,21],
      [2,24],[1,15,1,39],[1,15,1,39],[2,30],[1,21,1,45],[2,17],[1,8,1,32],
      [2,23],[2,23],[2,26],[1,17,1,41],[2,13],[2,16],[2,19],[2,19],
      [1,10,1,34],[1,13,1,37],[1,8,2,32],[2,14,1,38],[3,20],[1,2,2,26],
      [2,20,1,44],[3,26],[1,8,2,32],[2,14,1,38],[2,16,1,40],[3,22],[1,4,2,28],
      [2,10,1,34],[3,28],[1,10,2,34],[2,16,1,40],[3,22],[3,24],[1,6,2,30],
      [2,12,1,36],[3,18],[1,12,2,36],[2,18,1,42],[3,24],[1,6,2,30],[4,21],
      [4,23],[3,19,1,43],[1,3,3,27],[1,5,3,29],[4,25],[2,9,2,33],[2,11,2,35],
      [1,7,3,31],[3,15,1,39],[3,17,1,41],[2,13,2,37]],
 12=>[[1,0],[1,12],[1,1,1,11],[1,4,1,8],[1,5,1,7],[1,2,1,4,1,6],[1,6,1,8,1,10],
      [1,3,1,5,1,7,1,9]],
 13=>[[1,0],[1,6],[1,12],[1,18],[1,7,1,11],[1,4,1,8],[1,1,1,17],[1,5,1,13],
      [1,10,1,14],[1,7,1,11],[1,4,1,8,1,12],[1,2,1,6,1,10],[1,8,1,12,1,16],
      [1,6,1,10,1,14],[1,3,1,7,1,11,1,15],[1,5,2,9,1,13]],
 14=>[[1,0],[1,8],[1,16],[1,12],[1,20],[1,28],[1,15,1,21],[1,12,1,24],
      [1,9,1,27],[1,11,1,17],[1,8,1,20],[1,5,1,23],[1,7,1,13],[1,4,1,16],
      [1,1,1,19],[1,2,1,14,1,20],[1,8,1,14,1,26],[1,4,1,10,1,22],
      [1,10,1,16,1,22],[1,6,1,12,1,18],[1,6,1,18,1,24],[1,3,1,9,1,15,1,21],
      [1,5,1,11,1,17,1,23],[1,7,1,13,1,19,1,25]],
 15=>[[1,0],[1,6],[1,8],[1,14],[1,16],[1,22],[1,12],[1,18],[1,20],[1,26],
      [1,28],[1,34],[1,9,1,33],[1,12,1,24],[1,15,1,27],[1,15,1,27],[1,18,1,30],
      [2,21],[1,5,1,29],[1,8,1,20],[1,11,1,23],[1,11,1,23],[1,14,1,26],[2,17],
      [1,1,1,25],[1,4,1,16],[1,7,1,19],[1,7,1,19],[1,10,1,22],[2,13],[1,8,2,20],
      [1,2,1,14,1,26],[1,8,1,20,1,32],[2,14,1,26],[1,4,1,16,1,28],[2,10,1,22],
      [2,16,1,28],[1,10,2,22],[2,12,1,24],[1,6,2,18],[1,12,2,24],
      [1,6,1,18,1,30],[2,9,2,21],[2,11,2,23],[1,7,2,19,1,31],[1,3,2,15,1,27],
      [1,5,2,17,1,29],[2,13,2,25]],
 16=>[[1,0],[1,12],[1,24],[1,36],[1,48],[1,1,1,11],[1,7,1,17],[1,13,1,23],
      [1,19,1,29],[1,13,1,23],[1,19,1,29],[1,25,1,35],[1,25,1,35],[1,31,1,41],
      [1,37,1,47],[1,2,1,12,1,22],[1,6,1,16,1,26],[1,10,1,20,1,30],
      [1,10,1,20,1,30],[1,14,1,24,1,34],[1,18,1,28,1,38],[1,14,1,24,1,34],
      [1,18,1,28,1,38],[1,22,1,32,1,42],[1,26,1,36,1,46],[1,15,1,25,1,35,1,45],
      [1,17,2,27,1,37],[1,9,1,19,1,29,1,39],[1,11,2,21,1,31],
      [1,3,1,13,1,23,1,33],[1,20,2,30,1,40],[1,12,1,22,1,32,1,42],
      [1,14,2,24,1,34],[1,6,1,16,1,26,1,36],[1,8,2,18,1,28],[1,12,2,22,2,32],
      [1,4,1,14,1,24,1,34,1,44],[2,16,2,26,1,36],[1,8,1,18,2,28,1,38],
      [1,10,2,20,1,30,1,40],[1,5,2,15,2,25,1,35],[1,7,2,17,2,27,1,37],
      [1,9,2,19,2,29,1,39],[1,11,2,21,2,31,1,41],[1,13,2,23,2,33,1,43]],
 17=>[[1,0],[1,12],[1,24],[1,36],[1,48],[1,30],[1,42],[1,54],[1,66],[1,78],
      [1,11,1,31],[1,17,1,37],[1,13,1,53],[1,19,1,59],[1,13,1,53],[1,19,1,59],
      [1,25,1,65],[1,25,1,65],[1,31,1,71],[1,37,1,77],[1,1,1,41],[1,7,1,47],
      [1,35,1,55],[1,35,1,55],[1,41,1,61],[1,47,1,67],[1,23,1,43],[1,29,1,49],
      [1,23,1,43],[1,29,1,49],[1,2,1,22,1,42],[1,6,1,26,1,46],[1,10,1,30,1,50],
      [1,10,1,30,1,50],[1,14,1,34,1,54],[1,18,1,38,1,58],[1,14,1,34,1,54],
      [1,18,1,38,1,58],[1,22,1,42,1,62],[1,26,1,46,1,66],[1,12,1,32,1,52],
      [1,16,1,36,1,56],[1,20,1,40,1,60],[1,20,1,40,1,60],[1,24,1,44,1,64],
      [1,28,1,48,1,68],[1,24,1,44,1,64],[1,28,1,48,1,68],[1,32,1,52,1,72],
      [1,36,1,56,1,76],[1,15,1,35,1,55,1,75],[2,27,1,47,1,67],
      [1,19,2,39,1,59],[1,11,1,31,2,51],[1,3,1,23,1,43,1,63],
      [2,30,1,50,1,70],[1,22,2,42,1,62],[1,14,1,34,2,54],
      [1,6,1,26,1,46,1,66],[2,18,1,38,1,58],[1,25,2,45,1,65],[1,17,1,37,2,57],
      [1,9,1,29,1,49,1,69],[2,21,1,41,1,61],[1,13,2,33,1,53],[1,20,1,40,2,60],
      [1,12,1,32,1,52,1,72],[2,24,1,44,1,64],[1,16,2,36,1,56],[1,8,1,28,2,48],
      [1,12,2,32,2,52],[2,22,1,42,2,62],[1,4,1,24,2,44,1,64],
      [1,14,2,34,1,54,1,74],[2,16,1,36,2,56],[2,26,2,46,1,66],
      [1,8,2,28,1,48,1,68],[1,18,2,38,2,58],[2,20,2,40,1,60],
      [1,10,1,30,2,50,1,70],[2,15,2,35,2,55],[2,17,2,37,2,57],[2,19,2,39,2,59],
      [1,11,2,31,2,51,1,71],[1,13,2,33,2,53,1,73],[1,5,2,25,2,45,1,65],
      [1,7,2,27,2,47,1,67],[1,9,2,29,2,49,1,69],[2,21,2,41,2,61],
      [2,23,2,43,2,63]],
 18=>[[1,0],[1,12],[1,24],[1,36],[1,48],[1,20],[1,32],[1,44],[1,56],[1,68],
      [1,40],[1,52],[1,64],[1,76],[1,88],[1,21,1,51],[1,27,1,57],[1,33,1,63],
      [1,39,1,69],[1,33,1,63],[1,39,1,69],[1,45,1,75],[1,45,1,75],[1,51,1,81],
      [1,57,1,87],[1,11,1,41],[1,17,1,47],[1,23,1,53],[1,29,1,59],[1,23,1,53],
      [1,29,1,59],[1,35,1,65],[1,35,1,65],[1,41,1,71],[1,47,1,77],[1,1,1,31],
      [1,7,1,37],[1,13,1,43],[1,19,1,49],[1,13,1,43],[1,19,1,49],[1,25,1,55],
      [1,25,1,55],[1,31,1,61],[1,37,1,67],[1,2,1,32,1,62],[2,26,1,56],
      [1,20,2,50],[1,20,2,50],[1,14,1,44,1,74],[2,38,1,68],[1,14,1,44,1,74],
      [2,38,1,68],[1,32,2,62],[1,26,1,56,1,86],[2,22,1,52],[1,16,2,46],
      [1,10,1,40,1,70],[1,10,1,40,1,70],[2,34,1,64],[1,28,2,58],[2,34,1,64],
      [1,28,2,58],[1,22,1,52,1,82],[2,46,1,76],[1,12,2,42],[1,6,1,36,1,66],
      [2,30,1,60],[2,30,1,60],[1,24,2,54],[1,18,1,48,1,78],[1,24,2,54],
      [1,18,1,48,1,78],[2,42,1,72],[1,36,2,66],[1,15,2,45,1,75],[2,27,2,57],
      [1,9,2,39,1,69],[2,21,2,51],[1,3,2,33,1,63],[2,35,2,65],[1,17,2,47,1,77],
      [2,29,2,59],[1,11,2,41,1,71],[2,23,2,53],[1,25,2,55,1,85],[2,37,2,67],
      [1,19,2,49,1,79],[2,31,2,61],[1,13,2,43,1,73],[2,30,2,60],
      [1,12,2,42,1,72],[2,24,2,54],[1,6,2,36,1,66],[2,18,2,48],[1,20,2,50,1,80],
      [2,32,2,62],[1,14,2,44,1,74],[2,26,2,56],[1,8,2,38,1,68],[2,40,2,70],
      [1,22,2,52,1,82],[2,34,2,64],[1,16,2,46,1,76],[2,28,2,58],
      [1,12,2,42,2,72],[3,32,2,62],[2,22,3,52],[2,24,2,54,1,84],
      [1,14,3,44,1,74],[1,4,2,34,2,64],[3,36,2,66],[2,26,3,56],
      [2,16,2,46,1,76],[1,18,3,48,1,78],[1,8,2,38,2,68],[3,28,2,58],
      [2,30,3,60],[2,20,2,50,1,80],[1,10,3,40,1,70],[3,25,3,55],
      [1,7,3,37,2,67],[2,19,3,49,1,79],[3,31,3,61],[1,13,3,43,2,73],
      [1,5,3,35,2,65],[2,17,3,47,1,77],[3,29,3,59],[1,11,3,41,2,71],
      [2,23,3,53,1,83],[2,15,3,45,1,75],[3,27,3,57],[1,9,3,39,2,69],
      [2,21,3,51,1,81],[3,33,3,63]],
 19=>[[1,0],[1,12],[1,24],[1,36],[1,48],[1,20],[1,32],[1,44],[1,56],[1,68],
      [1,40],[1,52],[1,64],[1,76],[1,88],[1,30],[1,42],[1,54],[1,66],[1,78],
      [1,50],[1,62],[1,74],[1,86],[1,98],[1,70],[1,82],[1,94],[1,106],[1,118],
      [2,51],[2,57],[1,33,1,93],[1,39,1,99],[1,33,1,93],[1,39,1,99],
      [1,45,1,105],[1,45,1,105],[1,51,1,111],[1,57,1,117],[2,41],[2,47],[2,53],
      [2,59],[2,53],[2,59],[1,35,1,95],[1,35,1,95],[1,41,1,101],[1,47,1,107],
      [2,31],[2,37],[2,43],[2,49],[2,43],[2,49],[2,55],[2,55],[1,31,1,91],
      [1,37,1,97],[1,21,1,81],[1,27,1,87],[2,63],[2,69],[2,63],[2,69],[2,75],
      [2,75],[2,81],[2,87],[1,11,1,71],[1,17,1,77],[1,23,1,83],[1,29,1,89],
      [1,23,1,83],[1,29,1,89],[2,65],[2,65],[2,71],[2,77],[1,1,1,61],[1,7,1,67],
      [1,13,1,73],[1,19,1,79],[1,13,1,73],[1,19,1,79],[1,25,1,85],[1,25,1,85],
      [2,61],[2,67],[1,2,2,62],[2,26,1,86],[3,50],[3,50],[1,14,2,74],
      [2,38,1,98],[1,14,2,74],[2,38,1,98],[3,62],[1,26,2,86],[2,32,1,92],[3,56],      [1,20,2,80],[1,20,2,80],[2,44,1,104],[3,68],[2,44,1,104],[3,68],
      [1,32,2,92],[2,56,1,116],[2,22,1,82],[3,46],[1,10,2,70],[1,10,2,70],
      [2,34,1,94],[3,58],[2,34,1,94],[3,58],[1,22,2,82],[2,46,1,106],[3,52],
      [1,16,2,76],[2,40,1,100],[2,40,1,100],[3,64],[1,28,2,88],[3,64],
      [1,28,2,88],[2,52,1,112],[3,76],[3,42],[1,6,2,66],[2,30,1,90],[2,30,1,90],
      [3,54],[1,18,2,78],[3,54],[1,18,2,78],[2,42,1,102],[3,66],[1,12,2,72],
      [2,36,1,96],[3,60],[3,60],[1,24,2,84],[2,48,1,108],[1,24,2,84],
      [2,48,1,108],[3,72],[1,36,2,96],[1,15,3,75],[2,27,2,87],[3,39,1,99],
      [4,51],[1,3,3,63],[2,35,2,95],[3,47,1,107],[4,59],[1,11,3,71],[2,23,2,83],
      [3,55,1,115],[4,67],[1,19,3,79],[2,31,2,91],[3,43,1,103],[2,30,2,90],
      [3,42,1,102],[4,54],[1,6,3,66],[2,18,2,78],[3,50,1,110],[4,62],
      [1,14,3,74],[2,26,2,86],[3,38,1,98],[4,70],[1,22,3,82],[2,34,2,94],
      [3,46,1,106],[4,58],[3,45,1,105],[4,57],[1,9,3,69],[2,21,2,81],
      [3,33,1,93],[4,65],[1,17,3,77],[2,29,2,89],[3,41,1,101],[4,53],
      [1,25,3,85],[2,37,2,97],[3,49,1,109],[4,61],[1,13,3,73],[4,60],
      [1,12,3,72],[2,24,2,84],[3,36,1,96],[4,48],[1,20,3,80],[2,32,2,92],
      [3,44,1,104],[4,56],[1,8,3,68],[2,40,2,100],[3,52,1,112],[4,64],
      [1,16,3,76],[2,28,2,88],[1,12,4,72],[3,32,2,92],[5,52],[3,42,2,102],
      [5,62],[2,22,3,82],[2,24,3,84],[4,44,1,104],[1,4,4,64],[4,54,1,114],
      [1,14,4,74],[3,34,2,94],[3,36,2,96],[5,56],[2,16,3,76],[5,66],[2,26,3,86],
      [4,46,1,106],[4,48,1,108],[1,8,4,68],[3,28,2,88],[1,18,4,78],[3,38,2,98],
      [5,58],[5,60],[2,20,3,80],[4,40,1,100],[2,30,3,90],[4,50,1,110],
      [1,10,4,70],[3,25,3,85],[1,7,5,67],[5,49,1,109],[6,61],[4,43,2,103],
      [4,35,2,95],[2,17,4,77],[6,59],[1,11,5,71],[5,53,1,113],[5,45,1,105],
      [3,27,3,87],[1,9,5,69],[2,21,4,81],[6,63],[6,55],[4,37,2,97],[2,19,4,79],
      [3,31,3,91],[1,13,5,73],[1,5,5,65],[5,47,1,107],[3,29,3,89],[4,41,2,101],
      [2,23,4,83],[2,15,4,75],[6,57],[4,39,2,99],[5,51,1,111],[3,33,3,93]],
 20=>[[1,0],[1,20],[1,40],[1,21,1,39],[1,27,1,33],[1,11,1,29],[1,17,1,23],
      [1,1,1,19],[1,7,1,13],[1,2,1,20,1,38],[1,14,1,20,1,26],[1,10,1,22,1,28],
      [1,10,1,16,1,34],[1,12,1,18,1,30],[1,6,1,24,1,30],[1,3,1,9,1,21,1,27],
      [1,11,1,17,1,23,1,29],[1,13,1,19,1,31,1,37],[1,6,1,12,1,18,1,24],
      [1,8,1,14,1,26,1,32],[1,16,1,22,1,28,1,34],[1,12,1,18,1,24,1,30,1,36],
      [1,8,1,14,1,20,1,26,1,32],[1,4,1,10,1,16,1,22,1,28],
      [1,7,1,13,1,19,2,25,1,31],[1,9,2,15,1,21,1,27,1,33],
      [1,5,1,11,1,17,1,23,1,29,1,35]],
 21=>[[1,0],[1,20],[1,40],[1,30],[1,50],[1,70],[1,39,1,51],[1,33,1,57],
      [1,21,1,69],[1,27,1,63],[1,29,1,41],[1,23,1,47],[1,17,1,53],[1,11,1,59],
      [1,19,1,31],[1,13,1,37],[1,7,1,43],[1,1,1,49],[1,2,1,38,1,50],
      [1,14,1,26,1,50],[1,20,1,32,1,68],[1,20,1,44,1,56],[1,10,1,22,1,58],
      [1,10,1,34,1,46],[1,28,1,40,1,52],[1,16,1,40,1,64],[1,18,1,30,1,42],
      [1,6,1,30,1,54],[1,12,1,48,1,60],[1,24,1,36,1,60],[1,3,1,27,1,39,1,51],
      [1,11,1,23,1,47,1,59],[1,19,1,31,1,43,1,67],[1,6,1,18,1,42,1,54],
      [1,14,1,26,1,38,1,62],[1,22,1,34,1,46,1,58],[1,9,1,21,1,33,1,57],
      [1,17,1,29,1,41,1,53],[1,13,1,37,1,49,1,61],[1,12,1,24,1,36,1,48],
      [1,8,1,32,1,44,1,56],[1,16,1,28,1,52,1,64],[1,12,1,24,1,36,1,48,1,60],
      [1,8,1,20,1,32,1,44,1,56],[1,4,1,16,1,28,1,40,1,52],
      [1,18,1,30,1,42,1,54,1,66],[1,14,1,26,1,38,1,50,1,62],
      [1,10,1,22,1,34,1,46,1,58],[1,13,2,25,1,37,1,49,1,61],
      [1,7,1,19,1,31,1,43,2,55],[1,11,1,23,2,35,1,47,1,59],
      [1,5,1,17,1,29,1,41,1,53,1,65],[1,9,1,21,1,33,2,45,1,57],
      [2,15,1,27,1,39,1,51,1,63]],
 22=>[[1,0],[1,30],[1,11,1,19],[1,13,1,17],[1,1,1,29],[1,7,1,23],
      [1,2,1,10,1,18],[1,6,1,10,1,14],[1,12,1,20,1,28],[1,16,1,20,1,24],
      [1,3,1,11,1,19,1,27],[1,6,1,14,1,18,1,22],[1,9,1,13,1,17,1,21],
      [1,8,1,12,1,16,1,24],[1,4,1,8,1,12,1,16,1,20],[1,10,1,14,1,18,1,22,1,26],
      [1,7,1,11,2,15,1,19,1,23],[1,5,1,9,1,13,1,17,1,21,1,25]],
 34=>[[1,0],[1,4],[1,8],[1,5,1,7],[1,3,1,5],[1,1,1,3],[1,2,1,4,1,6]],
 35=>[[1,0],[1,4],[1,8],[1,4],[1,8],[1,12],[1,8],[1,12],[1,16],[1,9,1,15],
      [1,7,1,13],[1,5,1,11],[1,7,1,13],[1,5,1,11],[1,3,1,9],[1,5,1,11],
      [1,3,1,9],[1,1,1,7],[1,4,2,10],[1,2,1,8,1,14],[2,6,1,12]],
 36=>[[1,0],[1,4],[1,8],[1,6],[1,10],[1,14],[1,5,1,13],[1,3,1,11],[1,3,1,7],
      [1,7,1,11],[1,1,1,9],[1,5,1,9],[1,2,1,6,1,10],[1,4,1,8,1,12]],
 37=>[[1,0],[1,4],[1,8],[1,4],[1,8],[1,12],[1,8],[1,12],[1,16],[1,6],[1,10],
      [1,14],[1,10],[1,14],[1,18],[1,14],[1,18],[1,22],[1,9,1,21],[1,7,1,19],
      [2,11],[1,7,1,19],[2,11],[2,9],[2,11],[2,9],[2,7],[2,15],[2,13],
      [1,5,1,17],[2,13],[1,5,1,17],[1,3,1,15],[1,5,1,17],[1,3,1,15],[1,1,1,13],
      [3,10],[1,4,2,16],[1,2,2,14],[2,8,1,20],[2,6,1,18],[3,12]],
 38=>[[1,0],[1,6],[1,12],[1,18],[1,1,1,5],[1,4,1,8],[1,7,1,11],[1,7,1,11],
      [1,10,1,14],[1,13,1,17],[1,8,1,12,1,16],[1,6,1,10,1,14],[1,4,1,8,1,12],
      [1,2,1,6,1,10],[1,5,2,9,1,13],[1,3,1,7,1,11,1,15]],
 39=>[[1,0],[1,6],[1,12],[1,18],[1,12],[1,18],[1,24],[1,30],[1,5,1,13],
      [1,4,1,20],[1,7,1,23],[1,7,1,23],[1,10,1,26],[1,13,1,29],[1,1,1,17],
      [1,14,1,22],[1,17,1,25],[1,11,1,19],[1,11,1,19],[1,8,1,16],
      [1,8,1,16,1,24],[1,6,1,14,1,22],[1,4,1,12,1,20],[1,2,1,10,1,18],
      [1,12,1,20,1,28],[1,10,1,18,1,26],[1,8,1,16,1,24],[1,6,1,14,1,22],
      [2,9,1,17,1,25],[1,7,2,15,1,23],[1,3,1,11,1,19,1,27],[1,5,1,13,2,21]],
310=>[[1,0],[1,6],[1,12],[1,18],[1,8],[1,14],[1,20],[1,26],[1,16],[1,22],[1,28],
      [1,34],[1,9,1,21],[1,12,1,24],[1,15,1,27],[1,15,1,27],[1,18,1,30],
      [1,21,1,33],[1,5,1,17],[1,8,1,20],[1,11,1,23],[1,11,1,23],[1,14,1,26],
      [1,17,1,29],[1,1,1,13],[1,4,1,16],[1,7,1,19],[1,7,1,19],[1,10,1,22],
      [1,13,1,25],[1,8,1,20,1,32],[2,14,1,26],[1,8,2,20],[1,2,1,14,1,26],
      [2,16,1,28],[1,10,2,22],[1,4,1,16,1,28],[2,10,1,22],[1,12,2,24],
      [1,6,1,18,1,30],[2,12,1,24],[1,6,2,18],[2,9,2,21],[2,11,2,23],
      [1,7,2,19,1,31],[1,3,2,15,1,27],[1,5,2,17,1,29],[2,13,2,25]],
311=>[[1,0],[1,6],[1,12],[1,18],[1,8],[1,14],[1,20],[1,26],[1,16],[1,22],[1,28],
      [1,34],[1,12],[1,18],[1,24],[1,30],[1,20],[1,26],[1,32],[1,38],[1,28],
      [1,34],[1,40],[1,46],[1,9,1,33],[1,12,1,36],[2,27],[2,27],[1,18,1,42],
      [2,33],[1,5,1,29],[2,20],[1,11,1,35],[1,11,1,35],[1,14,1,38],[2,29],
      [1,1,1,25],[1,4,1,28],[1,7,1,31],[1,7,1,31],[2,22],[2,25],[2,21],[2,24],
      [1,15,1,39],[1,15,1,39],[2,30],[1,21,1,45],[2,17],[1,8,1,32],[2,23],
      [2,23],[2,26],[1,17,1,41],[2,13],[2,16],[2,19],[2,19],[1,10,1,34],
      [1,13,1,37],[1,8,2,32],[2,14,1,38],[3,20],[1,2,2,26],[2,20,1,44],[3,26],
      [1,8,2,32],[2,14,1,38],[2,16,1,40],[3,22],[1,4,2,28],[2,10,1,34],[3,28],
      [1,10,2,34],[2,16,1,40],[3,22],[3,24],[1,6,2,30],[2,12,1,36],[3,18],
      [1,12,2,36],[2,18,1,42],[3,24],[1,6,2,30],[4,21],[4,23],[3,19,1,43],
      [1,3,3,27],[1,5,3,29],[4,25],[2,9,2,33],[2,11,2,35],[1,7,3,31],
      [3,15,1,39],[3,17,1,41],[2,13,2,37]],
312=>[[1,0],[1,12],[1,1,1,11],[1,4,1,8],[1,5,1,7],[1,2,1,4,1,6],[1,6,1,8,1,10],
      [1,3,1,5,1,7,1,9]],
313=>[[1,0],[1,6],[1,12],[1,18],[1,7,1,11],[1,4,1,8],[1,1,1,17],[1,5,1,13],
      [1,10,1,14],[1,7,1,11],[1,4,1,8,1,12],[1,2,1,6,1,10],[1,8,1,12,1,16],
      [1,6,1,10,1,14],[1,3,1,7,1,11,1,15],[1,5,2,9,1,13]],
314=>[[1,0],[1,8],[1,16],[1,12],[1,20],[1,28],[1,15,1,21],[1,12,1,24],
      [1,9,1,27],[1,11,1,17],[1,8,1,20],[1,5,1,23],[1,7,1,13],[1,4,1,16],
      [1,1,1,19],[1,2,1,14,1,20],[1,8,1,14,1,26],[1,4,1,10,1,22],
      [1,10,1,16,1,22],[1,6,1,12,1,18],[1,6,1,18,1,24],[1,3,1,9,1,15,1,21],
      [1,5,1,11,1,17,1,23],[1,7,1,13,1,19,1,25]],
315=>[[1,0],[1,6],[1,8],[1,14],[1,16],[1,22],[1,12],[1,18],[1,20],[1,26],[1,28],
      [1,34],[1,9,1,33],[1,12,1,24],[1,15,1,27],[1,15,1,27],[1,18,1,30],
      [2,21],[1,5,1,29],[1,8,1,20],[1,11,1,23],[1,11,1,23],[1,14,1,26],[2,17],
      [1,1,1,25],[1,4,1,16],[1,7,1,19],[1,7,1,19],[1,10,1,22],[2,13],
      [1,8,2,20],[1,2,1,14,1,26],[1,8,1,20,1,32],[2,14,1,26],[1,4,1,16,1,28],
      [2,10,1,22],[2,16,1,28],[1,10,2,22],[2,12,1,24],[1,6,2,18],[1,12,2,24],
      [1,6,1,18,1,30],[2,9,2,21],[2,11,2,23],[1,7,2,19,1,31],[1,3,2,15,1,27],
      [1,5,2,17,1,29],[2,13,2,25]],
316=>[[1,0],[1,12],[1,24],[1,36],[1,48],[1,1,1,11],[1,7,1,17],[1,13,1,23],
      [1,19,1,29],[1,13,1,23],[1,19,1,29],[1,25,1,35],[1,25,1,35],[1,31,1,41],
      [1,37,1,47],[1,2,1,12,1,22],[1,6,1,16,1,26],[1,10,1,20,1,30],
      [1,10,1,20,1,30],[1,14,1,24,1,34],[1,18,1,28,1,38],[1,14,1,24,1,34],
      [1,18,1,28,1,38],[1,22,1,32,1,42],[1,26,1,36,1,46],[1,15,1,25,1,35,1,45],
      [1,17,2,27,1,37],[1,9,1,19,1,29,1,39],[1,11,2,21,1,31],
      [1,3,1,13,1,23,1,33],[1,20,2,30,1,40],[1,12,1,22,1,32,1,42],
      [1,14,2,24,1,34],[1,6,1,16,1,26,1,36],[1,8,2,18,1,28],[1,12,2,22,2,32],
      [1,4,1,14,1,24,1,34,1,44],[2,16,2,26,1,36],[1,8,1,18,2,28,1,38],
      [1,10,2,20,1,30,1,40],[1,5,2,15,2,25,1,35],[1,7,2,17,2,27,1,37],
      [1,9,2,19,2,29,1,39],[1,11,2,21,2,31,1,41],[1,13,2,23,2,33,1,43]],
317=>[[1,0],[1,12],[1,24],[1,36],[1,48],[1,30],[1,42],[1,54],[1,66],[1,78],
      [1,11,1,31],[1,17,1,37],[1,13,1,53],[1,19,1,59],[1,13,1,53],[1,19,1,59],
      [1,25,1,65],[1,25,1,65],[1,31,1,71],[1,37,1,77],[1,1,1,41],[1,7,1,47],
      [1,35,1,55],[1,35,1,55],[1,41,1,61],[1,47,1,67],[1,23,1,43],[1,29,1,49],
      [1,23,1,43],[1,29,1,49],[1,2,1,22,1,42],[1,6,1,26,1,46],[1,10,1,30,1,50],
      [1,10,1,30,1,50],[1,14,1,34,1,54],[1,18,1,38,1,58],[1,14,1,34,1,54],
      [1,18,1,38,1,58],[1,22,1,42,1,62],[1,26,1,46,1,66],[1,12,1,32,1,52],
      [1,16,1,36,1,56],[1,20,1,40,1,60],[1,20,1,40,1,60],[1,24,1,44,1,64],
      [1,28,1,48,1,68],[1,24,1,44,1,64],[1,28,1,48,1,68],[1,32,1,52,1,72],
      [1,36,1,56,1,76],[1,15,1,35,1,55,1,75],[2,27,1,47,1,67],
      [1,19,2,39,1,59],[1,11,1,31,2,51],[1,3,1,23,1,43,1,63],[2,30,1,50,1,70],
      [1,22,2,42,1,62],[1,14,1,34,2,54],[1,6,1,26,1,46,1,66],[2,18,1,38,1,58],
      [1,25,2,45,1,65],[1,17,1,37,2,57],[1,9,1,29,1,49,1,69],[2,21,1,41,1,61],
      [1,13,2,33,1,53],[1,20,1,40,2,60],[1,12,1,32,1,52,1,72],[2,24,1,44,1,64],
      [1,16,2,36,1,56],[1,8,1,28,2,48],[1,12,2,32,2,52],[2,22,1,42,2,62],
      [1,4,1,24,2,44,1,64],[1,14,2,34,1,54,1,74],[2,16,1,36,2,56],
      [2,26,2,46,1,66],[1,8,2,28,1,48,1,68],[1,18,2,38,2,58],[2,20,2,40,1,60],
      [1,10,1,30,2,50,1,70],[2,15,2,35,2,55],[2,17,2,37,2,57],[2,19,2,39,2,59],
      [1,11,2,31,2,51,1,71],[1,13,2,33,2,53,1,73],[1,5,2,25,2,45,1,65],
      [1,7,2,27,2,47,1,67],[1,9,2,29,2,49,1,69],[2,21,2,41,2,61],
      [2,23,2,43,2,63]],
318=>[[1,0],[1,12],[1,24],[1,36],[1,48],[1,20],[1,32],[1,44],[1,56],[1,68],
      [1,40],[1,52],[1,64],[1,76],[1,88],[1,21,1,51],[1,27,1,57],[1,33,1,63],
      [1,39,1,69],[1,33,1,63],[1,39,1,69],[1,45,1,75],[1,45,1,75],[1,51,1,81],
      [1,57,1,87],[1,11,1,41],[1,17,1,47],[1,23,1,53],[1,29,1,59],[1,23,1,53],
      [1,29,1,59],[1,35,1,65],[1,35,1,65],[1,41,1,71],[1,47,1,77],[1,1,1,31],
      [1,7,1,37],[1,13,1,43],[1,19,1,49],[1,13,1,43],[1,19,1,49],[1,25,1,55],
      [1,25,1,55],[1,31,1,61],[1,37,1,67],[1,2,1,32,1,62],[2,26,1,56],
      [1,20,2,50],[1,20,2,50],[1,14,1,44,1,74],[2,38,1,68],[1,14,1,44,1,74],
      [2,38,1,68],[1,32,2,62],[1,26,1,56,1,86],[2,22,1,52],[1,16,2,46],
      [1,10,1,40,1,70],[1,10,1,40,1,70],[2,34,1,64],[1,28,2,58],[2,34,1,64],
      [1,28,2,58],[1,22,1,52,1,82],[2,46,1,76],[1,12,2,42],[1,6,1,36,1,66],
      [2,30,1,60],[2,30,1,60],[1,24,2,54],[1,18,1,48,1,78],[1,24,2,54],
      [1,18,1,48,1,78],[2,42,1,72],[1,36,2,66],[1,15,2,45,1,75],[2,27,2,57],
      [1,9,2,39,1,69],[2,21,2,51],[1,3,2,33,1,63],[2,35,2,65],[1,17,2,47,1,77],
      [2,29,2,59],[1,11,2,41,1,71],[2,23,2,53],[1,25,2,55,1,85],[2,37,2,67],
      [1,19,2,49,1,79],[2,31,2,61],[1,13,2,43,1,73],[2,30,2,60],
      [1,12,2,42,1,72],[2,24,2,54],[1,6,2,36,1,66],[2,18,2,48],[1,20,2,50,1,80],
      [2,32,2,62],[1,14,2,44,1,74],[2,26,2,56],[1,8,2,38,1,68],[2,40,2,70],
      [1,22,2,52,1,82],[2,34,2,64],[1,16,2,46,1,76],[2,28,2,58],
      [1,12,2,42,2,72],[3,32,2,62],[2,22,3,52],[2,24,2,54,1,84],
      [1,14,3,44,1,74],[1,4,2,34,2,64],[3,36,2,66],[2,26,3,56],[2,16,2,46,1,76],
      [1,18,3,48,1,78],[1,8,2,38,2,68],[3,28,2,58],[2,30,3,60],[2,20,2,50,1,80],
      [1,10,3,40,1,70],[3,25,3,55],[1,7,3,37,2,67],[2,19,3,49,1,79],[3,31,3,61],
      [1,13,3,43,2,73],[1,5,3,35,2,65],[2,17,3,47,1,77],[3,29,3,59],
      [1,11,3,41,2,71],[2,23,3,53,1,83],[2,15,3,45,1,75],[3,27,3,57],
      [1,9,3,39,2,69],[2,21,3,51,1,81],[3,33,3,63]],
319=>[[1,0],[1,12],[1,24],[1,36],[1,48],[1,20],[1,32],[1,44],[1,56],[1,68],
      [1,40],[1,52],[1,64],[1,76],[1,88],[1,30],[1,42],[1,54],[1,66],[1,78],
      [1,50],[1,62],[1,74],[1,86],[1,98],[1,70],[1,82],[1,94],[1,106],[1,118],
      [2,51],[2,57],[1,33,1,93],[1,39,1,99],[1,33,1,93],[1,39,1,99],
      [1,45,1,105],[1,45,1,105],[1,51,1,111],[1,57,1,117],[2,41],[2,47],[2,53],
      [2,59],[2,53],[2,59],[1,35,1,95],[1,35,1,95],[1,41,1,101],[1,47,1,107],
      [2,31],[2,37],[2,43],[2,49],[2,43],[2,49],[2,55],[2,55],[1,31,1,91],
      [1,37,1,97],[1,21,1,81],[1,27,1,87],[2,63],[2,69],[2,63],[2,69],[2,75],
      [2,75],[2,81],[2,87],[1,11,1,71],[1,17,1,77],[1,23,1,83],[1,29,1,89],
      [1,23,1,83],[1,29,1,89],[2,65],[2,65],[2,71],[2,77],[1,1,1,61],[1,7,1,67],
      [1,13,1,73],[1,19,1,79],[1,13,1,73],[1,19,1,79],[1,25,1,85],[1,25,1,85],
      [2,61],[2,67],[1,2,2,62],[2,26,1,86],[3,50],[3,50],[1,14,2,74],
      [2,38,1,98],[1,14,2,74],[2,38,1,98],[3,62],[1,26,2,86],[2,32,1,92],[3,56],
      [1,20,2,80],[1,20,2,80],[2,44,1,104],[3,68],[2,44,1,104],[3,68],
      [1,32,2,92],[2,56,1,116],[2,22,1,82],[3,46],[1,10,2,70],[1,10,2,70],
      [2,34,1,94],[3,58],[2,34,1,94],[3,58],[1,22,2,82],[2,46,1,106],[3,52],
      [1,16,2,76],[2,40,1,100],[2,40,1,100],[3,64],[1,28,2,88],[3,64],
      [1,28,2,88],[2,52,1,112],[3,76],[3,42],[1,6,2,66],[2,30,1,90],[2,30,1,90],
      [3,54],[1,18,2,78],[3,54],[1,18,2,78],[2,42,1,102],[3,66],[1,12,2,72],
      [2,36,1,96],[3,60],[3,60],[1,24,2,84],[2,48,1,108],[1,24,2,84],
      [2,48,1,108],[3,72],[1,36,2,96],[1,15,3,75],[2,27,2,87],[3,39,1,99],
      [4,51],[1,3,3,63],[2,35,2,95],[3,47,1,107],[4,59],[1,11,3,71],[2,23,2,83],
      [3,55,1,115],[4,67],[1,19,3,79],[2,31,2,91],[3,43,1,103],[2,30,2,90],
      [3,42,1,102],[4,54],[1,6,3,66],[2,18,2,78],[3,50,1,110],[4,62],
      [1,14,3,74],[2,26,2,86],[3,38,1,98],[4,70],[1,22,3,82],[2,34,2,94],
      [3,46,1,106],[4,58],[3,45,1,105],[4,57],[1,9,3,69],[2,21,2,81],
      [3,33,1,93],[4,65],[1,17,3,77],[2,29,2,89],[3,41,1,101],[4,53],
      [1,25,3,85],[2,37,2,97],[3,49,1,109],[4,61],[1,13,3,73],[4,60],
      [1,12,3,72],[2,24,2,84],[3,36,1,96],[4,48],[1,20,3,80],[2,32,2,92],
      [3,44,1,104],[4,56],[1,8,3,68],[2,40,2,100],[3,52,1,112],[4,64],
      [1,16,3,76],[2,28,2,88],[1,12,4,72],[3,32,2,92],[5,52],[3,42,2,102],
      [5,62],[2,22,3,82],[2,24,3,84],[4,44,1,104],[1,4,4,64],[4,54,1,114],
      [1,14,4,74],[3,34,2,94],[3,36,2,96],[5,56],[2,16,3,76],[5,66],[2,26,3,86],
      [4,46,1,106],[4,48,1,108],[1,8,4,68],[3,28,2,88],[1,18,4,78],[3,38,2,98],
      [5,58],[5,60],[2,20,3,80],[4,40,1,100],[2,30,3,90],[4,50,1,110],
      [1,10,4,70],[3,25,3,85],[1,7,5,67],[5,49,1,109],[6,61],[4,43,2,103],
      [4,35,2,95],[2,17,4,77],[6,59],[1,11,5,71],[5,53,1,113],[5,45,1,105],
      [3,27,3,87],[1,9,5,69],[2,21,4,81],[6,63],[6,55],[4,37,2,97],[2,19,4,79],
      [3,31,3,91],[1,13,5,73],[1,5,5,65],[5,47,1,107],[3,29,3,89],[4,41,2,101],
      [2,23,4,83],[2,15,4,75],[6,57],[4,39,2,99],[5,51,1,111],[3,33,3,93]],
320=>[[1,0],[1,20],[1,40],[1,21,1,39],[1,27,1,33],[1,11,1,29],[1,17,1,23],
      [1,1,1,19],[1,7,1,13],[1,2,1,20,1,38],[1,14,1,20,1,26],[1,10,1,22,1,28],
      [1,10,1,16,1,34],[1,12,1,18,1,30],[1,6,1,24,1,30],[1,3,1,9,1,21,1,27],
      [1,11,1,17,1,23,1,29],[1,13,1,19,1,31,1,37],[1,6,1,12,1,18,1,24],
      [1,8,1,14,1,26,1,32],[1,16,1,22,1,28,1,34],[1,12,1,18,1,24,1,30,1,36],
      [1,8,1,14,1,20,1,26,1,32],[1,4,1,10,1,16,1,22,1,28],
      [1,7,1,13,1,19,2,25,1,31],[1,9,2,15,1,21,1,27,1,33],
      [1,5,1,11,1,17,1,23,1,29,1,35]],
321=>[[1,0],[1,20],[1,40],[1,30],[1,50],[1,70],[1,39,1,51],[1,33,1,57],
      [1,21,1,69],[1,27,1,63],[1,29,1,41],[1,23,1,47],[1,17,1,53],[1,11,1,59],
      [1,19,1,31],[1,13,1,37],[1,7,1,43],[1,1,1,49],[1,2,1,38,1,50],
      [1,14,1,26,1,50],[1,20,1,32,1,68],[1,20,1,44,1,56],[1,10,1,22,1,58],
      [1,10,1,34,1,46],[1,28,1,40,1,52],[1,16,1,40,1,64],[1,18,1,30,1,42],
      [1,6,1,30,1,54],[1,12,1,48,1,60],[1,24,1,36,1,60],[1,3,1,27,1,39,1,51],
      [1,11,1,23,1,47,1,59],[1,19,1,31,1,43,1,67],[1,6,1,18,1,42,1,54],
      [1,14,1,26,1,38,1,62],[1,22,1,34,1,46,1,58],[1,9,1,21,1,33,1,57],
      [1,17,1,29,1,41,1,53],[1,13,1,37,1,49,1,61],[1,12,1,24,1,36,1,48],
      [1,8,1,32,1,44,1,56],[1,16,1,28,1,52,1,64],[1,12,1,24,1,36,1,48,1,60],
      [1,8,1,20,1,32,1,44,1,56],[1,4,1,16,1,28,1,40,1,52],
      [1,18,1,30,1,42,1,54,1,66],[1,14,1,26,1,38,1,50,1,62],
      [1,10,1,22,1,34,1,46,1,58],[1,13,2,25,1,37,1,49,1,61],
      [1,7,1,19,1,31,1,43,2,55],[1,11,1,23,2,35,1,47,1,59],
      [1,5,1,17,1,29,1,41,1,53,1,65],[1,9,1,21,1,33,2,45,1,57],
      [2,15,1,27,1,39,1,51,1,63]],
322=>[[1,0],[1,30],[1,11,1,19],[1,13,1,17],[1,1,1,29],[1,7,1,23],
      [1,2,1,10,1,18],[1,6,1,10,1,14],[1,12,1,20,1,28],[1,16,1,20,1,24],
      [1,3,1,11,1,19,1,27],[1,6,1,14,1,18,1,22],[1,9,1,13,1,17,1,21],
      [1,8,1,12,1,16,1,24],[1,4,1,8,1,12,1,16,1,20],
      [1,10,1,14,1,18,1,22,1,26],[1,7,1,11,2,15,1,19,1,23],
      [1,5,1,9,1,13,1,17,1,21,1,25]])
  d[x]
end

This isn’t the source of your problem, as you’ve noticed already, but I believe that global anonymous function definitions result in type unstable functions because they aren’t constant to the compiler. For globally scoped functions, you should use function f(x) end syntax instead.

As already noted above, that’s not exactly usual Julia style. d should instead be a global constant, and f(x) = d[x] (I’d question the need to define such a function in the first place, but…). That said, the style doesn’t affect compilation latency. However, interestingly enough Julia 1.0 takes only 2 seconds for me to compile this function:

julia> @time f(4) # first call, including compilation
  2.515081 seconds (7.51 M allocations: 350.298 MiB, 5.63% gc time)
7-element Array{Array{Int64,1},1}:
 [1, 0]            
 [1, 4]            
 [1, 8]            
 [1, 5, 1, 7]      
 [1, 3, 1, 5]      
 [1, 1, 1, 3]      
 [1, 2, 1, 4, 1, 6]

julia> @time f(4) # second call, without compilation
  0.000131 seconds (2.11 k allocations: 245.953 KiB)
7-element Array{Array{Int64,1},1}:
 [1, 0]            
 [1, 4]            
 [1, 8]            
 [1, 5, 1, 7]      
 [1, 3, 1, 5]      
 [1, 1, 1, 3]      
 [1, 2, 1, 4, 1, 6]

julia> versioninfo()
Julia Version 1.0.5
Commit 3af96bcefc (2019-09-09 19:06 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

Could you post this example so we can see if we can improve compilation time in these cases?

It is difficult to give the example with polynomials since it also uses a big part of my huge package
Gapjm.jl. Imagine that a list [1,2,3,4] in the example is replaced by something like [1+x+2y^2+4x^3] where x,y,z are arguments to the function. But is not the example I gave already an example of something going wrong?

  • The time is exponential in the length of the data (if you double the length of the Dict definition the time is multiplied by 5 or 10).
  • From Giordano’s report it compiled quickly on Julia 1.0.5 so it is like a regression.
  • Why does the dictionary definition compile so slow inside a function?

By the way as already discussed I do prefer writing functions as function f(x) rather than f=function(x) but:

  • In recent julia (at least 1.7.2 which I use) it seems to make no performance difference (it was different with older julia)
  • The @time is only reported correctly with f=function(x). I also wonder why?

You may want to open an issue in GitHub. Since this seems to be a bug deep into Julia’s internals, I’m not sure you’ll get much help here.

Edit: issue opened at Excessive compilation time (regression) · Issue #45395 · JuliaLang/julia · GitHub.

This is answered by @time docstring:

help?> @time
  @time

  A macro to execute an expression, printing the time it took to execute, the number of allocations, and the total number of bytes its execution caused to be allocated, before returning the value of the
  expression. Any time spent garbage collecting (gc) or compiling is shown as a percentage.

  In some cases the system will look inside the @time expression and compile some of the called code before execution of the top-level expression begins. When that happens, some compilation time will not be
  counted. To include this time you can run @time @eval ....

You have to use @time @eval to always include compilation time when using @time.

2 Likes