Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slowness in compiling the library #8

Open
JasonGross opened this issue Jan 19, 2014 · 68 comments
Open

Slowness in compiling the library #8

JasonGross opened this issue Jan 19, 2014 · 68 comments

Comments

@JasonGross
Copy link

When I compile the library with Coq 8.4 and time how long it takes to make each file, I get

0.10    pathnotations
0.17    topos/epis_monos
0.18    limits/terminal
0.20    limits/initial
0.21    HLevel_n_is_of_hlevel_Sn
0.24    limits/aux_lemmas_HoTT
0.31    category_hset
0.43    whiskering
0.46    auxiliary_lemmas_HoTT
0.70    rezk_completion
0.86    precategories
1.03    yoneda
1.12    limits/cones
1.12    sub_precategories
4.71    equivalences
6.99    functors_transformations
9.29    precomp_fully_faithful
32.22   precomp_ess_surj
69.37   limits/pullbacks

(Admittedly, the HoTT library takes around three times as long, and I don't have a good sense of how complicated the constructions in precomp_ess_surj and limits/pullbacks.)

At least a third of the time in limits/pullbacks, probably much more, is spent checking trivial lemmas which are slow due to nested sigma types. It's plausible that Matthieu's polyproj branch fixes this, but if you're interested in fixing it before that lands for 8.5, you can replace nested sigmas with records (or, possibly just define custom projections for each nested sigma, so that you never use the bare projections from a sigma type).

@DanGrayson
Copy link
Contributor

How do bare projections slow things down?

And don't you have to use each bare projection at least once, to define the corresponding unbare ones?

@JasonGross
Copy link
Author

Whenever you use something like apply (pr2 (pr2 (pr1 (pr2 (pr2 Pb) e h k H)))). (PullbackArrow_PullbackPr2), Coq duplicates essentially the entire type of the nested sigma for every single projection. If you Set Printing All and Print PullbackArrow_PullbackPr2, you will see a giant term. Coq is bad at giant terms, and gets slow. If instead you define your projections in parts, with the most general types available, Coq will only see a small term at any given point in time. Coq doesn't care what you use under the hood, it only cares about how big the (non-normalized) term is that it sees. There's some more detail in 2.3 and 2.5 of the paper I'm working on at http://people.csail.mit.edu/jgross/category-coq-experience/category-coq-experience.pdf. ( @benediktahrens, this is the current draft of the paper that I sent you a while ago, and that I mentioned to you more recently as including a comparison of formalizations; it's not done yet, but it's getting close). @DanGrayson, if you do take a look at the sections in that paper and find them unclear, could you let me know?

@DanGrayson
Copy link
Contributor

Thanks for the link to the paper! I looked at 2.3 and 2.5, so it seems I
should try out defining total2 as a primitive projection and see if it runs
Foundations2, etc., faster under Mathieu's polyproj branch with "Set
Primitive Projections". Eta for primitive records already works, and that
would be useful, too. But short of doing that, I wonder what your
suggestion "define your projections in parts, with the most general types
available" actually means!

On Sun, Jan 19, 2014 at 4:18 PM, Jason Gross [email protected]:

Whenever you use something like apply (pr2 (pr2 (pr1 (pr2 (pr2 Pb) e h k
H)))). (PullbackArrow_PullbackPr2), Coq duplicates essentially the entire
type of the nested sigma for every single projection. If you Set Printing
All and Print PullbackArrow_PullbackPr2, you will see a giant term. Coq
is bad at giant terms, and gets slow. If instead you define your
projections in parts, with the most general types available, Coq will only
see a small term at any given point in time. Coq doesn't care what you use
under the hood, it only cares about how big the (non-normalized) term is
that it sees. There's some more detail in 2.3 and 2.5 of the paper I'm
working on at
http://people.csail.mit.edu/jgross/category-coq-experience/category-coq-experience.pdf.
( @bened! iktahrens https://github.com/benediktahrens, this is the
current draft of the paper that I sent you a while ago, and that I
mentioned to you more recently as including a comparison of formalizations;
it's not done yet, but it's getting close). @DanGraysonhttps://github.com/DanGrayson,
if you do take a look at the sections in that paper and find them unclear,
could you let me know?


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-32720201
.

@JasonGross
Copy link
Author

For example, in the issig tactics, using eta3_sigma:

Definition eta3_sigma `{P : forall (a : A) (b : B a) (c : C a b), Type}
           (u : sigT (fun a => sigT (fun b => sigT (P a b))))
  : (u.1; (u.2.1; (u.2.2.1; u.2.2.2))) = u
  := match u with existT x (existT y (existT z w)) => 1 end.

is sometimes an order of magnitude or more faster than regenerating the same proof term on the fly with specific types and arguments filled in---and the definition of eta3_sigma itself takes very little time to Coq. Similarly, if define (pr2 (pr2 (pr1 foo))) as some constant which takes, say an is_pullback (which only takes a few arguments itself), then Coq never sees the implicit arguments to pr2 (pr2 (pr1, and so doesn't slow down because of them.

@JasonGross
Copy link
Author

You might also be interested about my brain-dump about speed in Coq at HoTT/Coq-HoTT#157 (comment).

@DanGrayson
Copy link
Contributor

Re: "If you Set Printing All and Print PullbackArrow_PullbackPr2, you will see a giant term. "

You were right, and wc showed it had 291000 words in it! I think I have to understand that better. I'll experiment...

@benediktahrens
Copy link
Owner

precomp_ess_surj contains a quite lengthy proof which I am not going to refactor; also, since it proves an hprop, one can savely opacify it and forget about it.
limits/pullbacks is different, and one should try to make it fast. However, I am reluctant to invent a lot of names for particular projections. Speed seems less important for me than conceptual simplicity, and polymorphism (as in polymorphic projections) is one of the features providing simplicity.
In summary, I think that work on speed should be made on the level of Coq, not on the level of individual libraries.

Nonetheless, your measurements will help to identify bottlenecks and thus to improve on speed, so thanks a lot!

@DanGrayson
Copy link
Contributor

By the way, one can't always be totally comfortable with tacking a Qed on the end of a proof -- the statement of PullbackArrow_PullbackPr2 itself has up to 4 nested projections, and applying the lemma to arguments might result in a gigantic term, momentarily. I suppose.

@DanGrayson
Copy link
Contributor

Hmm, I find nothing conceptually simple about a term like (pr2 (pr2 (pr1 (pr2 (pr2 Pb) e h k H)))) appearing in a proof. Who can read that?

@JasonGross
Copy link
Author

and applying the lemma to arguments might result in a gigantic term, momentarily

Only if you need to unfold it. If you don't unfold it, Coq doesn't care how big it really is, because it's hidden. And Qed actually doesn't help that much, in my experience; it mainly helps when Coq tries (and would fail) to unify two things, one of which is gigantic, but they're not obviously different.

Hmm, I find nothing conceptually simple about a term like (pr2 (pr2 (pr1 (pr2 (pr2 Pb) e h k H)))) appearing in a proof. Who can read that?

To me, it says "there's nothing deep going on here, I'm just defining a projection of Pb", and then I'd try to infer which projection it is from the name of the lemma and its type. I almost certainly wouldn't try to trace the first and second projections.

@vladimirias
Copy link

Can someone please post the same table for 8.3?
Vladimir.

On Jan 19, 2014, at 3:58 PM, Jason Gross [email protected] wrote:

When I compile the library with Coq 8.4 and time how long it takes to make each file, I get

0.10 pathnotations
0.17 topos/epis_monos
0.18 limits/terminal
0.20 limits/initial
0.21 HLevel_n_is_of_hlevel_Sn
0.24 limits/aux_lemmas_HoTT
0.31 category_hset
0.43 whiskering
0.46 auxiliary_lemmas_HoTT
0.70 rezk_completion
0.86 precategories
1.03 yoneda
1.12 limits/cones
1.12 sub_precategories
4.71 equivalences
6.99 functors_transformations
9.29 precomp_fully_faithful
32.22 precomp_ess_surj
69.37 limits/pullbacks
(Admittedly, the HoTT library takes around three times as long, and I don't have a good sense of how complicated the constructions in precomp_ess_surj and limits/pullbacks.)

At least a third of the time in limits/pullbacks, probably much more, is spent checking trivial lemmas which are slow due to nested sigma types. It's plausible that Matthieu's polyproj branch fixes this, but if you're interested in fixing it before that lands for 8.5, you can replace nested sigmas with records (or, possibly just define custom projections for each nested sigma, so that you never use the bare projections from a sigma type).


Reply to this email directly or view it on GitHub.

@DanGrayson
Copy link
Contributor

I get this:

25.37 (v8.4) limits/pullbacks
10.18 (v8.4) precomp_ess_surj
3.08 (v8.4) precomp_fully_faithful
2.40 (v8.4) functors_transformations
1.74 (v8.4) equivalences
0.51 (v8.4) sub_precategories
0.47 (v8.4) limits/cones
0.42 (v8.4) precategories
0.36 (v8.4) rezk_completion
0.35 (v8.4) yoneda
0.25 (v8.4) auxiliary_lemmas_HoTT
0.21 (v8.4) whiskering
0.19 (v8.4) pathnotations
0.17 (v8.4) category_hset
0.15 (v8.4) limits/aux_lemmas_HoTT
0.14 (v8.4) HLevel_n_is_of_hlevel_Sn
0.13 (v8.4) topos/epis_monos
0.13 (v8.4) limits/terminal
0.13 (v8.4) limits/initial

23.56 (v8.3) limits/pullbacks
13.96 (v8.3) precomp_ess_surj
3.72 (v8.3) precomp_fully_faithful
2.50 (v8.3) functors_transformations
1.80 (v8.3) equivalences
0.48 (v8.3) limits/cones
0.44 (v8.3) sub_precategories
0.40 (v8.3) precategories
0.37 (v8.3) yoneda
0.31 (v8.3) rezk_completion
0.22 (v8.3) auxiliary_lemmas_HoTT
0.21 (v8.3) whiskering
0.16 (v8.3) category_hset
0.13 (v8.3) limits/aux_lemmas_HoTT
0.12 (v8.3) topos/epis_monos
0.11 (v8.3) limits/terminal
0.11 (v8.3) limits/initial
0.11 (v8.3) HLevel_n_is_of_hlevel_Sn
0.08 (v8.3) pathnotations

@benediktahrens
Copy link
Owner

Is there a similarly detailed measurement for Foundations?

On 01/22/2014 03:39 PM, Daniel R. Grayson wrote:

I get this:

25.37 (v8.4) limits/pullbacks
10.18 (v8.4) precomp_ess_surj
3.08 (v8.4) precomp_fully_faithful
2.40 (v8.4) functors_transformations
1.74 (v8.4) equivalences
0.51 (v8.4) sub_precategories
0.47 (v8.4) limits/cones
0.42 (v8.4) precategories
0.36 (v8.4) rezk_completion
0.35 (v8.4) yoneda
0.25 (v8.4) auxiliary_lemmas_HoTT
0.21 (v8.4) whiskering
0.19 (v8.4) pathnotations
0.17 (v8.4) category_hset
0.15 (v8.4) limits/aux_lemmas_HoTT
0.14 (v8.4) HLevel_n_is_of_hlevel_Sn
0.13 (v8.4) topos/epis_monos
0.13 (v8.4) limits/terminal
0.13 (v8.4) limits/initial

23.56 (v8.3) limits/pullbacks
13.96 (v8.3) precomp_ess_surj
3.72 (v8.3) precomp_fully_faithful
2.50 (v8.3) functors_transformations
1.80 (v8.3) equivalences
0.48 (v8.3) limits/cones
0.44 (v8.3) sub_precategories
0.40 (v8.3) precategories
0.37 (v8.3) yoneda
0.31 (v8.3) rezk_completion
0.22 (v8.3) auxiliary_lemmas_HoTT
0.21 (v8.3) whiskering
0.16 (v8.3) category_hset
0.13 (v8.3) limits/aux_lemmas_HoTT
0.12 (v8.3) topos/epis_monos
0.11 (v8.3) limits/terminal
0.11 (v8.3) limits/initial
0.11 (v8.3) HLevel_n_is_of_hlevel_Sn
0.08 (v8.3) pathnotations


Reply to this email directly or view it on GitHub:
#8 (comment)

@DanGrayson
Copy link
Contributor

89.66 (v8.4) hlevel2/algebra1d
46.61 (v8.4) hlevel2/algebra1b
29.90 (v8.4) hlevel2/algebra1c
26.38 (v8.4) Generalities/uu0
17.76 (v8.4) hlevel2/hq
9.24 (v8.4) hlevel2/hSet
6.51 (v8.4) hlevel2/hz
4.75 (v8.4) hlevel2/finitesets
1.01 (v8.4) hlevel2/algebra1a
0.70 (v8.4) hlevel2/hnat
0.49 (v8.4) hlevel2/stnfsets
0.17 (v8.4) hlevel1/hProp
0.14 (v8.4) Proof_of_Extensionality/funextfun
0.08 (v8.4) Generalities/uuu

14.26 (v8.3) hlevel2/hq
10.73 (v8.3) hlevel2/algebra1c
9.26 (v8.3) Generalities/uu0
7.65 (v8.3) hlevel2/algebra1b
7.09 (v8.3) hlevel2/hz
6.45 (v8.3) hlevel2/algebra1d
3.07 (v8.3) hlevel2/finitesets
0.98 (v8.3) hlevel2/hSet
0.95 (v8.3) hlevel2/algebra1a
0.63 (v8.3) hlevel2/hnat
0.45 (v8.3) hlevel2/stnfsets
0.14 (v8.3) hlevel1/hProp
0.10 (v8.3) Proof_of_Extensionality/funextfun
0.06 (v8.3) Generalities/uuu

@JasonGross
Copy link
Author

If you are interested, you can pass COQC = '"/usr/bin/time" -f "$$* (user: %U mem: %M ko)" $$(COQBIN)coqc' to coq_makefile, and then whenever you make, you will get timings. If you want sorted timings, you can do something like make 2>&1 | tee timings && grep user: timings | sed s'/^\(.*\) (user: \(.*\) mem: \(.*\))$/\2s\t\3\t\1/g' | sort -h. I generally add targets to my Makefile so that I can just do something like make pretty-timed or ./make-pretty-timed.sh to make these targets. There is also code at https://github.com/HoTT/HoTT/tree/master/etc/timing for autogenerating a nice table that compares new times to old times, which I include into most commits that I make.

@DanGrayson
Copy link
Contributor

I was wondering how you did that -- under Mac OS X, GNU time is not
installed, so I've just installed it.

On Wed, Jan 22, 2014 at 11:40 AM, Jason Gross [email protected]:

If you are interested, you can pass COQC = '"/usr/bin/time" -f "$$*
(user: %U mem: %M ko)" $$(COQBIN)coqc' to coq_makefile, and then whenever
you make, you will get timings. If you want sorted timings, you can do
something like make 2>&1 | tee timings && grep user: timings | sed
s'/^(.) (user: (.) mem: (.*))$/\2s\t\3\t\1/g' | sort -h. I
generally add targets to my Makefile so that I can just do something like make
pretty-timed or ./make-pretty-timed.sh to make these targets. There is
also code at https://github.com/HoTT/HoTT/tree/master/etc/timing for
autogenerating a nice table that compares new times to old times, which I
include into most commits that I make.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33041042
.

@JasonGross
Copy link
Author

I got the trick from trunk's coq_makefile (rather, from HoTT/coq's), which by default has an option TIMED so that if you pass make TIMED=1, if invokes coqc with that prefix. Also, you may have to play with the number of dollar signs before (COQBIN); two if you pass it from your own Makefile, or one if you pass it from the command line directly.

@benediktahrens
Copy link
Owner

Thanks, that's very interesting:

  • in RC, there is no increase in compile time
  • consequently, in RC the ranking stayed more or less the same between
    8.3 and 8.4, whereas in Foundations, it gets all mixed up
  • some files in RC actually had decreased compile time with 8.4, whereas
    for Foundations compilation takes longer with 8.4 for all files

Some files in Foundations take 10 times longer (hSet, algebra1d). It
might be worthwile investigating what particular construction there
takes so much longer, if any can be pointed out.

On 01/22/2014 05:06 PM, Daniel R. Grayson wrote:

89.66 (v8.4) hlevel2/algebra1d
46.61 (v8.4) hlevel2/algebra1b
29.90 (v8.4) hlevel2/algebra1c
26.38 (v8.4) Generalities/uu0
17.76 (v8.4) hlevel2/hq
9.24 (v8.4) hlevel2/hSet
6.51 (v8.4) hlevel2/hz
4.75 (v8.4) hlevel2/finitesets
1.01 (v8.4) hlevel2/algebra1a
0.70 (v8.4) hlevel2/hnat
0.49 (v8.4) hlevel2/stnfsets
0.17 (v8.4) hlevel1/hProp
0.14 (v8.4) Proof_of_Extensionality/funextfun
0.08 (v8.4) Generalities/uuu

14.26 (v8.3) hlevel2/hq
10.73 (v8.3) hlevel2/algebra1c
9.26 (v8.3) Generalities/uu0
7.65 (v8.3) hlevel2/algebra1b
7.09 (v8.3) hlevel2/hz
6.45 (v8.3) hlevel2/algebra1d
3.07 (v8.3) hlevel2/finitesets
0.98 (v8.3) hlevel2/hSet
0.95 (v8.3) hlevel2/algebra1a
0.63 (v8.3) hlevel2/hnat
0.45 (v8.3) hlevel2/stnfsets
0.14 (v8.3) hlevel1/hProp
0.10 (v8.3) Proof_of_Extensionality/funextfun
0.06 (v8.3) Generalities/uuu


Reply to this email directly or view it on GitHub:
#8 (comment)

@JasonGross
Copy link
Author

The trunk version of Coq has a -time flag, which will print out times for each individual statement. This might help.

@DanGrayson
Copy link
Contributor

I happen to have a patched version of the trunk so we can try that out.
But remind me what
turns off the new convention about whether arguments of constructor are
implicit.

On Wed, Jan 22, 2014 at 3:10 PM, Jason Gross [email protected]:

The trunk version of Coq has a -time flag, which will print out times for
each individual statement. This might help.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33062261
.

@JasonGross
Copy link
Author

I think it's Set Asymmetric Patterns?

-Jason
On Jan 22, 2014 12:33 PM, "Daniel R. Grayson" [email protected]
wrote:

I happen to have a patched version of the trunk so we can try that out.
But remind me what
turns off the new convention about whether arguments of constructor are
implicit.

On Wed, Jan 22, 2014 at 3:10 PM, Jason Gross [email protected]:

The trunk version of Coq has a -time flag, which will print out times
for
each individual statement. This might help.


Reply to this email directly or view it on GitHub<
https://github.com/benediktahrens/rezk_completion/issues/8#issuecomment-33062261>

.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33064680
.

@DanGrayson
Copy link
Contributor

The -time option works, and produces tons of output like this:

Chars 134257 - 134271 [split~with~f.] 0. secs (0.u,0.s)
Chars 134272 - 134327 [assert~(forall~t~:~T,~paths~(g...] 0. secs (0.u,0.s)
Chars 134328 - 134335 [intro.] 0. secs (0.u,0.s)
Chars 134336 - 134365 [apply~homottranspost2t1t1t2.] 2.268 secs (2.266u,0.001s)
Chars 134366 - 134421 [assert~(forall~t~:~T,~paths~(f...] 0. secs (0.u,0.s)
Chars 134422 - 134429 [intro.] 0. secs (0.u,0.s)
Chars 134431 - 134460 [apply~homottranspost2t1t1t2.] 2.326 secs (2.326u,0.s)
Chars 134461 - 134491 [apply~(gradth~_~_~egf~efg).] 0. secs (0.u,0.s)
Chars 134492 - 134501 [Defined.] 2.235 secs (2.234u,0.s)
Chars 134506 - 134680 [Lemma~pathsfuntransposoft1~{T~...] 0. secs (0.u,0.s)
Chars 134681 - 134688 [Proof.] 0. secs (0.u,0.s)
Chars 134689 - 134697 [intros.] 0. secs (0.u,0.s)
Chars 134698 - 134718 [unfold~funtranspos.] 0. secs (0.u,0.s)
Chars 134719 - 134762 [rewrite~(pathsrecomplfxtoy~t1~...] 0.001 secs (0.001u,0.s)
Chars 134763 - 134777 [apply~idpath.] 0. secs (0.u,0.s)
Chars 134779 - 134788 [Defined.] 0. secs (0.u,0.s)

@JasonGross
Copy link
Author

You can pipe it through | sed s'/^\(Chars .*\) \([^ ]\+ secs\)/\2\t\1 /g' | sort -h to get the slowest things at the bottom.

@DanGrayson
Copy link
Contributor

Or just pipe it through sort -gk 6

@DanGrayson
Copy link
Contributor

Here are the top ten offenders:

make topten
./hlevel2/algebra1d.v:38175-38271: [apply~~(rngaddhrelandfun~~~~~(...] 32.521 secs (32.5u,0.022s)
./hlevel2/algebra1d.v:37706-37801: [apply~~(rngmultgtandfun~~~~~(r...] 32.437 secs (32.409u,0.028s)
./Generalities/uu0.v:214875-214884: [Defined.] 6.444 secs (6.438u,0.005s)
./hlevel2/algebra1b.v:76174-76194: [apply~quotrellogeq.] 5.807 secs (5.802u,0.004s)
./hlevel2/algebra1b.v:75748-75767: [apply~quotrelimpl.] 5.784 secs (5.781u,0.003s)
./hlevel2/algebra1c.v:80877-80940: [apply~(invertibilityinabmonoid...] 5.1 secs (5.096u,0.003s)
./hlevel2/hSet.v:72908-72922: [apply~idpath.] 4.81 secs (4.802u,0.007s)
./hlevel2/algebra1c.v:76587-76646: [apply~(commax~(abmonoidfrac~(r...] 2.979 secs (2.971u,0.008s)
./hlevel2/algebra1c.v:80323-80379: [apply~(pr2~(abmonoidfrac~(rngm...] 2.964 secs (2.956u,0.007s)
./hlevel2/algebra1b.v:78413-78433: [apply~isdecquotrel.] 2.897 secs (2.895u,0.002s)

@JasonGross
Copy link
Author

Is ./hlevel2/hSet.v:72908-72922 any faster if you use exact idpath rather than apply?

@DanGrayson
Copy link
Contributor

I think I'll work on the big guys first. Often I find that apply in 8.4 is
worse than in 8.3, and when it's the problem, as it is here, the first
thing to do is to replace it by "exact".

On Wed, Jan 22, 2014 at 9:05 PM, Jason Gross [email protected]:

Is ./hlevel2/hSet.v:72908-72922 any faster if you use exact idpath rather
than apply?


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33090745
.

@DanGrayson
Copy link
Contributor

I got the two big guys, but using "exact" on idpath didn't help (yet):

make topten
./Generalities/uu0.v:214875-214884: [Defined.] 6.37 secs (6.364u,0.006s)
./hlevel2/algebra1b.v:76239-76259: [apply~quotrellogeq.] 5.803 secs (5.797u,0.006s)
./hlevel2/algebra1c.v:80877-80940: [apply~(invertibilityinabmonoid...] 5.173 secs (5.166u,0.006s)
./hlevel2/hSet.v:72908-72925: [exact~(idpath~_).] 5.164 secs (5.147u,0.01s)
./hlevel2/algebra1c.v:80323-80379: [apply~(pr2~(abmonoidfrac~(rngm...] 3.046 secs (3.038u,0.007s)
./hlevel2/algebra1c.v:76587-76646: [apply~(commax~(abmonoidfrac~(r...] 2.971 secs (2.96u,0.011s)
./hlevel2/algebra1b.v:78501-78521: [apply~isdecquotrel.] 2.91 secs (2.908u,0.002s)
./hlevel2/algebra1b.v:72440-72462: [apply~iseqrelquotrel.] 2.9 secs (2.898u,0.002s)
./hlevel2/algebra1b.v:70939-70960: [apply~issymmquotrel.] 2.9 secs (2.899u,0.001s)
./hlevel2/algebra1b.v:71439-71460: [apply~isreflquotrel.] 2.895 secs (2.894u,0.001s)

@DanGrayson
Copy link
Contributor

That cuts algebra1d from 90 seconds to

28.25 sec, 1782857728 bytes: hlevel2/algebra1d

@benediktahrens
Copy link
Owner

On 01/23/2014 06:34 AM, Daniel R. Grayson wrote:

That cuts algebra1d from 90 seconds to

28.25 sec, 1782857728 bytes: hlevel2/algebra1d

Awesome.
Would it make sense to try with opacified versions of some of the lemmas?

@DanGrayson
Copy link
Contributor

Compile from scratch with

make COQTIME=yes

first.

On Thu, Jan 23, 2014 at 10:58 AM, benediktahrens
[email protected]:

@DanGrayson https://github.com/DanGrayson: I have copied your Makefile
from Foundations2 to RezkCompletion, but make topten does not seem to work
for me: when the code is already compiled, I get
ahrens@alien:/git/benediktahrens/rezk_completion$ make topten
ahrens@alien:
/git/benediktahrens/rezk_completion$
and after a cleaning, make topten only computes the dependencies.
How is make topten supposed to work?


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33136902
.

@DanGrayson
Copy link
Contributor

And use the patched coq trunk you'll find in my "coq" repository, which
includes a working
"-time" option since yesterday.

On Thu, Jan 23, 2014 at 11:48 AM, Daniel R. Grayson [email protected]:

Compile from scratch with

make COQTIME=yes

first.

On Thu, Jan 23, 2014 at 10:58 AM, benediktahrens <[email protected]

wrote:

@DanGrayson https://github.com/DanGrayson: I have copied your Makefile
from Foundations2 to RezkCompletion, but make topten does not seem to work
for me: when the code is already compiled, I get
ahrens@alien:/git/benediktahrens/rezk_completion$ make topten
ahrens@alien:
/git/benediktahrens/rezk_completion$
and after a cleaning, make topten only computes the dependencies.
How is make topten supposed to work?


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33136902
.

@benediktahrens
Copy link
Owner

Thanks. Is the native code compilation responsible for that increase in
compilation time?

: compiling hlevel2/algebra1b.v ; >hlevel2/algebra1b.timing \time -f "%U
sec, %M bytes: hlevel2/algebra1b" coqc -q -R . Foundations
-indices-matter -no-sharing hlevel2/algebra1b
/tmp/camlasm235e34.s: Assembler messages:
/tmp/camlasm235e34.s:2645057: Error: symbol `.L200000' is already defined
File "./hlevel2/NFoundations_hlevel2_algebra1b.native", line 1,
characters 0-1:
Error: Assembler error, input left in file /tmp/camlasm235e34.s
Error: Could not compile the library to native code. Skipping.
122.22 sec, 316576 bytes: hlevel2/algebra1b

Is there a way to turn that off, by any chance?

On 01/23/2014 05:52 PM, Daniel R. Grayson wrote:

And use the patched coq trunk you'll find in my "coq" repository, which
includes a working
"-time" option since yesterday.

On Thu, Jan 23, 2014 at 11:48 AM, Daniel R. Grayson [email protected]:

Compile from scratch with

make COQTIME=yes

first.

On Thu, Jan 23, 2014 at 10:58 AM, benediktahrens <[email protected]

wrote:

@DanGrayson https://github.com/DanGrayson: I have copied your Makefile
from Foundations2 to RezkCompletion, but make topten does not seem to work
for me: when the code is already compiled, I get
ahrens@alien:/git/benediktahrens/rezk_completion$ make topten
ahrens@alien:
/git/benediktahrens/rezk_completion$
and after a cleaning, make topten only computes the dependencies.
How is make topten supposed to work?


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33136902
.


Reply to this email directly or view it on GitHub:
#8 (comment)

@JasonGross
Copy link
Author

Did you pass -debug to ./configure? Alternatively, you should pass -no-native-compiler to ./configure. (I can't recall whether removing -debug or adding -no-native-compiler fixed my problems with assembly.)

@benediktahrens
Copy link
Owner

Commit 98cc2f0 introduces an
intermediate projection for pullback, thus reducing the compile time
significantly.
I guess that as a rule of thumb, one should not compose more than two or
three pr{1,2}'s.

@benediktahrens
Copy link
Owner

It's weird, because I should be able to choose when compiling the Coq
library whether I want to have native compilation or not, no?
Anyway, I'll try your hints and recompile Coq. Thankfully I was given a
new machine...

On 01/23/2014 07:05 PM, Jason Gross wrote:

Did you pass -debug to ./configure? Alternatively, you should pass -no-native-compiler to ./configure. (I can't recall whether removing -debug or adding -no-native-compiler fixed my problems with assembly.)


Reply to this email directly or view it on GitHub:
#8 (comment)

@JasonGross
Copy link
Author

There might also be an option to pass to coqc, but I've had the problems when compiling the stdlib, so always pass my arguments to ./configure.

@benediktahrens
Copy link
Owner

"
Flag ignored by unification (but maybe not in trunk, or maybe not in
HoTT/coq, or maybe not in mattam82/coq/branch/polyproj?)
"

This seems to me to be the main question, or with typechecking rather
than unification, no?

@DanGrayson
Copy link
Contributor

Qed instead of Opaque speeds Foundations up by 33%, see DanGrayson/Foundations2@21de280

@DanGrayson
Copy link
Contributor

Native code compilation adds 20% to the time, and turning it off prevents an anomaly when compiling my K-theory stuff.

@DanGrayson
Copy link
Contributor

The option for coqc is called -no-native-compiler.

@vladimirias
Copy link

Dan,

did you send this to Matthieu?

V.

On Jan 22, 2014, at 11:06 AM, Daniel R. Grayson [email protected] wrote:

89.66 (v8.4) hlevel2/algebra1d
46.61 (v8.4) hlevel2/algebra1b
29.90 (v8.4) hlevel2/algebra1c
26.38 (v8.4) Generalities/uu0
17.76 (v8.4) hlevel2/hq
9.24 (v8.4) hlevel2/hSet
6.51 (v8.4) hlevel2/hz
4.75 (v8.4) hlevel2/finitesets
1.01 (v8.4) hlevel2/algebra1a
0.70 (v8.4) hlevel2/hnat
0.49 (v8.4) hlevel2/stnfsets
0.17 (v8.4) hlevel1/hProp
0.14 (v8.4) Proof_of_Extensionality/funextfun
0.08 (v8.4) Generalities/uuu

14.26 (v8.3) hlevel2/hq
10.73 (v8.3) hlevel2/algebra1c
9.26 (v8.3) Generalities/uu0
7.65 (v8.3) hlevel2/algebra1b
7.09 (v8.3) hlevel2/hz
6.45 (v8.3) hlevel2/algebra1d
3.07 (v8.3) hlevel2/finitesets
0.98 (v8.3) hlevel2/hSet
0.95 (v8.3) hlevel2/algebra1a
0.63 (v8.3) hlevel2/hnat
0.45 (v8.3) hlevel2/stnfsets
0.14 (v8.3) hlevel1/hProp
0.10 (v8.3) Proof_of_Extensionality/funextfun
0.06 (v8.3) Generalities/uuu


Reply to this email directly or view it on GitHub.

@vladimirias
Copy link

On Jan 23, 2014, at 12:34 AM, Daniel R. Grayson [email protected] wrote:

That cuts algebra1d from 90 seconds to

28.25 sec, 1782857728 bytes: hlevel2/algebra1d

what is the number 178.... about?

V.

@vladimirias
Copy link

It is great for now, but I am uncomfortable with the amount of hacking which one needs to apply where the system should work without any.

V.

On Jan 23, 2014, at 4:54 AM, benediktahrens [email protected] wrote:

On 01/23/2014 06:34 AM, Daniel R. Grayson wrote:

That cuts algebra1d from 90 seconds to

28.25 sec, 1782857728 bytes: hlevel2/algebra1d

Awesome.
Would it make sense to try with opacified versions of some of the lemmas?

Reply to this email directly or view it on GitHub.

@vladimirias
Copy link

There were no Qed's. Opaques were added to Defined's. Qed's are not good because there are proofs where I use "transparent" on constants which have been opaqued and this does not work with things which have been qed'ed.

V.

On Jan 23, 2014, at 8:55 AM, Daniel R. Grayson [email protected] wrote:

At some point Vladimir must have replaced a lot of Qed's with Opaque's, but
I hear that isn't as good. If you think so, too, I could just try
reverting all of those.

On Thu, Jan 23, 2014 at 4:54 AM, benediktahrens [email protected]:

On 01/23/2014 06:34 AM, Daniel R. Grayson wrote:

That cuts algebra1d from 90 seconds to

28.25 sec, 1782857728 bytes: hlevel2/algebra1d

Awesome.
Would it make sense to try with opacified versions of some of the lemmas?


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33110099
.


Reply to this email directly or view it on GitHub.

@vladimirias
Copy link

On Jan 23, 2014, at 9:21 AM, benediktahrens [email protected] wrote:

From the description on
http://coq.inria.fr/distrib/current/refman/Reference-Manual008.html#hevea_default447
it seems that Opaque renders opaque from a user point of view, but not
(completely) from the type-checking point of view.

Also, and maybe more importantly, "The scope of Opaque is limited to the
current section, or current file, unless the variant Global Opaque
qualid1 … qualidn is used."
So all the Opaque commands in early algebra files are not retained in
the later ones.

I am not sure that this has been intended. May be "Global Opaque" is Ok. But again, I do not think that it is a good idea to hck the library when the fault is with Coq.

V.

@benediktahrens
Copy link
Owner

Why do you call Qed'ing lemmas "hacking"?
From what I understand, we use Qed basically to avoid that terms which
have already been typechecked (when they were defined) get unfolded
later when being used and thus have to be typechecked again.

I agree that the performance regression from 8.3 to 8.4 is worrying, and
that Qed'ing is not a replacement for finding the reason for the regression.

But I think that opacifying some stuff in Foundations will be
unavoidable in the long run, when more mathematics is built upon it, in
order to avoid an explosion in the size of terms.
And for this it is not clear to me whether "Global Opaque" is
sufficient, because I don't know where this option is respected and
where it isn't. If we want to rely on it, we should have some Coq
developer explain its functionality to us and know if its features are
supposed to change in the future.

On 01/24/2014 01:23 PM, Vladimir Voevodsky wrote:

I am not sure that this has been intended. May be "Global Opaque" is
Ok. But again, I do not think that it is a good idea to hck the
library when the fault is with Coq.

@DanGrayson
Copy link
Contributor

Yes, the two constants you use Transparent with were left alone. And it's
easy enough to revert if you want to do it with another.

On Fri, Jan 24, 2014 at 7:21 AM, Vladimir Voevodsky <
[email protected]> wrote:

There were no Qed's. Opaques were added to Defined's. Qed's are not good
because there are proofs where I use "transparent" on constants which have
been opaqued and this does not work with things which have been qed'ed.

V.

On Jan 23, 2014, at 8:55 AM, Daniel R. Grayson [email protected]
wrote:

At some point Vladimir must have replaced a lot of Qed's with Opaque's,
but
I hear that isn't as good. If you think so, too, I could just try
reverting all of those.

On Thu, Jan 23, 2014 at 4:54 AM, benediktahrens <
[email protected]>wrote:

On 01/23/2014 06:34 AM, Daniel R. Grayson wrote:

That cuts algebra1d from 90 seconds to

28.25 sec, 1782857728 bytes: hlevel2/algebra1d

Awesome.
Would it make sense to try with opacified versions of some of the
lemmas?


Reply to this email directly or view it on GitHub<
https://github.com/benediktahrens/rezk_completion/issues/8#issuecomment-33110099>

.


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33218544
.

@DanGrayson
Copy link
Contributor

It's the number of bytes of memory used by coq.

On Fri, Jan 24, 2014 at 5:08 AM, Vladimir Voevodsky <
[email protected]> wrote:

On Jan 23, 2014, at 12:34 AM, Daniel R. Grayson [email protected]
wrote:

That cuts algebra1d from 90 seconds to

28.25 sec, 1782857728 bytes: hlevel2/algebra1d

what is the number 178.... about?

V.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33210972
.

@vladimirias
Copy link

On Jan 23, 2014, at 1:21 PM, benediktahrens [email protected] wrote:

Commit 98cc2f0 introduces an
intermediate projection for pullback, thus reducing the compile time
significantly.
I guess that as a rule of thumb, one should not compose more than two or
three pr{1,2}'s.

Why? The projection from, for example, commring to UU is much longer.

V.

@benediktahrens
Copy link
Owner

On 01/24/2014 02:25 PM, Vladimir Voevodsky wrote:

On Jan 23, 2014, at 1:21 PM, benediktahrens [email protected] wrote:

Commit 98cc2f0 introduces an
intermediate projection for pullback, thus reducing the compile time
significantly.
I guess that as a rule of thumb, one should not compose more than two or
three pr{1,2}'s.

Why? The projection from, for example, commring to UU is much longer.

What I really meant was that literally chaining many pr{1,2}'s is too
slow, as Jason also mentioned earlier in this thread.

E.g.

Definition foo := pr1 (pr2 (pr2 (pr1 (pr2 b)))))

will take long whereas

Definition bar b := pr2 (pr1 (pr2 b)))
Definition foo' := pr1 (pr2 (bar b))

will give acceptable compile times.

Since commrng is built "in stages", the projection from commrng to UU
looks like the second example.

@DanGrayson
Copy link
Contributor

No, I didn't send it to him, but feel free to do so.

On Fri, Jan 24, 2014 at 4:27 AM, Vladimir Voevodsky <
[email protected]> wrote:

Dan,

did you send this to Matthieu?

V.

On Jan 22, 2014, at 11:06 AM, Daniel R. Grayson [email protected]
wrote:

89.66 (v8.4) hlevel2/algebra1d
46.61 (v8.4) hlevel2/algebra1b
29.90 (v8.4) hlevel2/algebra1c
26.38 (v8.4) Generalities/uu0
17.76 (v8.4) hlevel2/hq
9.24 (v8.4) hlevel2/hSet
6.51 (v8.4) hlevel2/hz
4.75 (v8.4) hlevel2/finitesets
1.01 (v8.4) hlevel2/algebra1a
0.70 (v8.4) hlevel2/hnat
0.49 (v8.4) hlevel2/stnfsets
0.17 (v8.4) hlevel1/hProp
0.14 (v8.4) Proof_of_Extensionality/funextfun
0.08 (v8.4) Generalities/uuu

14.26 (v8.3) hlevel2/hq
10.73 (v8.3) hlevel2/algebra1c
9.26 (v8.3) Generalities/uu0
7.65 (v8.3) hlevel2/algebra1b
7.09 (v8.3) hlevel2/hz
6.45 (v8.3) hlevel2/algebra1d
3.07 (v8.3) hlevel2/finitesets
0.98 (v8.3) hlevel2/hSet
0.95 (v8.3) hlevel2/algebra1a
0.63 (v8.3) hlevel2/hnat
0.45 (v8.3) hlevel2/stnfsets
0.14 (v8.3) hlevel1/hProp
0.10 (v8.3) Proof_of_Extensionality/funextfun
0.06 (v8.3) Generalities/uuu


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33208421
.

@vladimirias
Copy link

On Jan 24, 2014, at 8:21 AM, Daniel R. Grayson [email protected] wrote:

Yes, the two constants you use Transparent with were left alone. And it's
easy enough to revert if you want to do it with another.

For our experimental work with the library it's Ok. But what about someone who wants to use the library without changing it (which is the way libraries are supposed to be used)?

V.

@DanGrayson
Copy link
Contributor

That's a good point, which I didn't consider. Perhaps I should undo it.
Is there any class of theorems that we could be certain would never need
unfolding? Benedikt, what about that point for your library?

On Fri, Jan 24, 2014 at 8:46 AM, Vladimir Voevodsky <
[email protected]> wrote:

On Jan 24, 2014, at 8:21 AM, Daniel R. Grayson [email protected]
wrote:

Yes, the two constants you use Transparent with were left alone. And
it's
easy enough to revert if you want to do it with another.

For our experimental work with the library it's Ok. But what about someone
who wants to use the library without changing it (which is the way
libraries are supposed to be used)?

V.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33223423
.

@benediktahrens
Copy link
Owner

On 01/24/2014 03:08 PM, Daniel R. Grayson wrote:

That's a good point, which I didn't consider. Perhaps I should undo it.
Is there any class of theorems that we could be certain would never need
unfolding? Benedikt, what about that point for your library?

RezkCompletion does not use any of the files in which you have replaced
Opaque by Qed.

It might be good to ask how HoTT is handling the issue. @JasonGross, are
there any guidelines for contributions to HoTT concerning this question?

I think there is a range of lemmas which can safely be closed by Qed,
such as any isofhlevel lemma, and in general many hprops.
But we should also not be afraid of getting it wrong: when people
stumble upon an opaque thing they need transparent, they can file an issue.

@mikeshulman
Copy link
Collaborator

I think the perspective of HoTT/HoTT (at least, my perspective) is that we are a long way from being able to build a library that most users can use without modification -- the whole project is still an experiment -- so we have no problem with switching Defineds and Qeds around as needed by users. I think the default is to Defined everything unless Qed seems to produce a significant speedup for some things.

@JasonGross
Copy link
Author

I follow a slightly different approach to the category theory contributions I've been making to HoTT/HoTT: Defined for everything that isn't an hProp, and for the hProps that are expected to sometimes reduce to refl (e.g., in composition of functors). Qed (rather, abstract) for the rest of the hProps.

@DanGrayson
Copy link
Contributor

It seems that gradth in Vladimir's u00 would be made Qed by your recipe,
since it returns isweq f, but that breaks later code, probably because the
proof needs to be unfolded to produce the inverse of f later on.

On Fri, Jan 24, 2014 at 3:02 PM, Jason Gross [email protected]:

I follow a slightly different approach to the category theory
contributions I've been making to HoTT/HoTT: Defined for everything that
isn't an hProp, and for the hProps that are expected to sometimes reduce to
refl (e.g., in composition of functors). Qed (rather, abstract) for the
rest of the hProps.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-33255686
.

@JasonGross
Copy link
Author

Ah, I should specify that the only hProps that I tend to encounter in the category theory stuff are proofs of equality and proofs of truncation. Even so, I sometimes need the proofs of equality to be partially transparent, because, for example, I need to remove instances of funext and play some other tricks to pull refls out of them. So I guess my rule isn't so hard and fast. My guess is that my inclination would be to make the inverse transparent, but the rest of the proof terms opaque (the section, retraction, adjointifcation coherence) opaque.

@vladimirias
Copy link

On Jan 24, 2014, at 9:08 AM, Daniel R. Grayson [email protected] wrote:

That's a good point, which I didn't consider. Perhaps I should undo it.
Is there any class of theorems that we could be certain would never need
unfolding?

I thought about it when I worked on Foundations and could not come up with any useful criterion.

V.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants