Skip to content

Remove the workarounds introduced in #1125#1365

Draft
pi8027 wants to merge 1 commit into
masterfrom
semi-modules-rm-perf-workarounds
Draft

Remove the workarounds introduced in #1125#1365
pi8027 wants to merge 1 commit into
masterfrom
semi-modules-rm-perf-workarounds

Conversation

@pi8027

@pi8027 pi8027 commented Mar 19, 2025

Copy link
Copy Markdown
Member
Motivation for this change

#1125 introduced some workarounds for performance issues with linear lemmas. This PR removes them, relying on the performance improvements introduced in Rocq 9.0.

Minimal TODO list
  • added changelog entries with doc/changelog/make-entry.sh
  • added corresponding documentation in the headers
  • tried to abide by the contribution guide
  • this PR contains an optimum number of meaningful commits

See this Checklist for details.

Automatic note to reviewers

Read this Checklist.

@pi8027 pi8027 added kind: clean-up This issure/PR is about cleaning up obsolete code, removing hacks, etc drops: coq 8.20 labels Mar 19, 2025
@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch 2 times, most recently from 40508a7 to bd7c788 Compare March 19, 2025 16:54
@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch 2 times, most recently from df61543 to c34342c Compare April 4, 2025 13:14

@pi8027 pi8027 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a performance comparison of the (* slow *) lines before/after this PR (c34342c) in Rocq 9.0.0.

EDIT 2025-11-06: I rebenched it in Rocq 9.1.0. The commit hash is bf7bc67.

Comment thread algebra/vector.v

Let vs2mx0 : @vs2mx K vT 0 = 0.
Proof. by rewrite /= linear0 genmx0. Qed.
Proof. by rewrite /= linear0 genmx0. Qed. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.002s -> 0.044s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.003s -> 0.002s

Comment thread algebra/vector.v
Lemma vlineP v1 v2 : reflect (exists k, v1 = k *: v2) (v1 \in <[v2]>)%VS.
Proof.
apply: (iffP idP) => [|[k ->]]; rewrite memvK genmxE ?linearZ ?scalemx_sub //.
apply: (iffP idP) => [|[k ->]]; rewrite memvK genmxE ?linearZ ?scalemx_sub //. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.011s -> 0.158s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.017s -> 0.014s

Comment thread algebra/vector.v
Proof.
split=> [|a u v]; rewrite !memvK 1?linear0 1?sub0mx // => Uu Uv.
by rewrite linearP addmx_sub ?scalemx_sub.
split=> [|a u v]; rewrite !memvK 1?linear0 1?sub0mx // => Uu Uv. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.005s -> 0.175s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.006s -> 0.008s

Comment thread algebra/vector.v
split=> [|a u v]; rewrite !memvK 1?linear0 1?sub0mx // => Uu Uv.
by rewrite linearP addmx_sub ?scalemx_sub.
split=> [|a u v]; rewrite !memvK 1?linear0 1?sub0mx // => Uu Uv. (* slow *)
by rewrite linearP addmx_sub ?scalemx_sub. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.006s -> 0.044s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.007s -> 0.007s

Comment thread algebra/vector.v

Lemma memv_add u v U V : u \in U -> v \in V -> u + v \in (U + V)%VS.
Proof. by rewrite !memvK genmxE linearD; apply: addmx_sub_adds. Qed.
Proof. by rewrite !memvK genmxE linearD; apply: addmx_sub_adds. Qed. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.005s -> 0.133s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.004s -> 0.005s

Comment thread character/character.v

Lemma xcfun_is_additive phi : additive (xcfun phi).
Proof. by move=> A B; rewrite /xcfun [gring_row _]linearB mulmxBl !mxE. Qed.
Proof. by move=> A B; rewrite /xcfun [gring_row _]linearB mulmxBl !mxE. Qed. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.033s -> 0.036s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.07s -> 0.071s

move=> Gx; apply/eqP; rewrite 2!mulmxA mul_rV_lin1 -subr_eq0 -mulmxBr /=.
rewrite uv0 // linearB /= mulmxBr vec_mxK; split. (* FIXME: slow *)
move=> Gx; apply/eqP; rewrite 2!mulmxA mul_rV_lin1 -subr_eq0 -mulmxBr.
rewrite uv0 // 2!linearB /= vec_mxK; split. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.032s -> 0.291s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth keeping the workaround here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.071s -> 0.998s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one sounds bad (with which version of Rocq?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rocq 9.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, then we should indeed keep the workaround here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, it's unclear if the slowdown comes from 1) the changes in instance declarations, 2) the changes in proofs, or 3) both. We should keep the whole workaround in place until we better understand the situation.

move=> A B RnA RnB /= eqAB; apply/eqP; rewrite -subr_eq0 -mxvec_eq0 -submx0.
rewrite -ker_irr_comp_op sub_capmx (sameP sub_kermxP eqP) mul_vec_lin.
by rewrite 2!raddfB /= eqAB subrr linear0 addmx_sub ?eqmx_opp /=.
by rewrite 2!linearB /= eqAB subrr linear0 addmx_sub ?eqmx_opp /=. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.064s -> 0.057s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.012s -> 0.138s

rewrite (mx_Schur irrG) ?subr_eq0 //; last first.
by apply: contraNneq nscal_rGx => ->; apply: scalar_mx_is_scalar.
rewrite -memmx_cent_envelop raddfB.
rewrite -memmx_cent_envelop linearB. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.029s -> 0.025s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.003s -> 0.061s

Proof. by apply: (canLR in_genK); rewrite in_gen0. Qed.

Lemma in_genN : {morph in_gen : W / - W}.
Proof. by move=> W; apply/matrixP=> i j; rewrite !mxE 4!(mulNmx, linearN). Qed. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.003s -> 0.246s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth keeping the workaround here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.003s -> 0.701s

@pi8027

pi8027 commented Apr 4, 2025

Copy link
Copy Markdown
Member Author

For vector.v, I hope its generalization to semi-vector spaces will further mitigate the issue. Most GRing.semilinear_linear should disappear anyway thanks to #1269.

@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch from c34342c to 40e81b7 Compare May 15, 2025 15:48
@Tragicus

Tragicus commented Jun 9, 2025

Copy link
Copy Markdown
Contributor

rocq-prover/rocq#20730 is 0.3% slower on master and 5% faster on this branch (than rocq/master). With the Rocq PR, this branch becomes 1% slower than master.

@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch from 40e81b7 to 8950dd5 Compare September 15, 2025 12:21
@pi8027

pi8027 commented Sep 15, 2025

Copy link
Copy Markdown
Member Author

I discarded the changes to poly.v and matrix.v: they were just removal of GRing.semilinear_linear which has been done in #1395 and #1398 (in the right way). I hope this will also be the case in mxpoly.v (#1269), vector.v, and qpoly.v, but the last two are non-trivial (#1269 (comment)).

@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch from 8950dd5 to 4dcae16 Compare September 17, 2025 08:26
@proux01 proux01 added this to the 2.6.0 milestone Sep 22, 2025
@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch from 4dcae16 to 672a31d Compare September 23, 2025 10:44
@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch from 672a31d to 6534948 Compare October 21, 2025 12:09
@pi8027

pi8027 commented Oct 21, 2025

Copy link
Copy Markdown
Member Author

This PR can probably be merged safely now. It would be nice to compare the performance of the (* slow *) lines before/after this PR using a recent version of Rocq (9.1 or master) before doing so.

@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch from 6534948 to d7f79ae Compare October 21, 2025 12:58
@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch from d7f79ae to 5623704 Compare November 3, 2025 12:14
@pi8027 pi8027 force-pushed the semi-modules-rm-perf-workarounds branch from 5623704 to bf7bc67 Compare November 6, 2025 15:28
Comment thread algebra/vector.v
Proof.
rewrite unlock /pinvmx rank_rV; case: negP => [[] | _].
by apply/eqP/rowP=> j; rewrite !mxE (tnth_nth 0) /= linear0 mxE.
by apply/eqP/rowP=> j; rewrite !mxE (tnth_nth 0) /= linear0 mxE. (* slow *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.005s -> 0.005s

@pi8027

pi8027 commented Nov 6, 2025

Copy link
Copy Markdown
Member Author

I rebenched this PR with Rocq 9.1.0. To sum up, I don't see any slowdown in vector.v anymore. However, mxrepresentation.v has become slower for unclear reasons. (It's a bit concerning to see that the master branch is already slower than before. Perhaps it's because of new structures?)

We should probably wait for rocq-prover/rocq#20730 at least.

@pi8027 pi8027 modified the milestones: 2.6.0, 2.7.0 Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drops: coq 8.20 kind: clean-up This issure/PR is about cleaning up obsolete code, removing hacks, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants