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

A few performance improvements #380

Merged
merged 5 commits into from
Sep 6, 2023

Conversation

proux01
Copy link
Contributor

@proux01 proux01 commented Aug 18, 2023

Compilation of MathComp:

  • before: 22:57 (1.53 GB)
    • HB.structure: 05:42
    • HB.instance: 02:31
    • HB.mixin: 00:19
    • HB.factory: 00:32
    • HB.builders: 00:23
    • HB.pack(_for): 00:15
  • after: 17.22 (1.27 GB)
    • HB.structure: 01:38
    • HB.instance: 02:21
    • HB.mixin: 00:18
    • HB.factory: 00:32
    • HB.builders: 00:23
    • HB.pack(_for): 00:15
  • mathcomp1: 06:16 (0.97 GB) (time x 2.77 (memory x 1.31))

Compilation of Analysis:

  • before: 26:24 (2.49 GB)
    • HB.structure: 03:22
    • HB.instance: 02:56
    • HB.mixin: 00:29
    • HB.factory: 00:27
    • HB.builders: 00:18
  • after: 20:54 (1.79 GB)
    • HB.structure: 01:02
    • HB.instance: 02:44
    • HB.mixin: 00:27
    • HB.factory: 00:25
    • HB.builders: 00:17
  • analysis master: 07:49 (1.55 GB) with HB 1.4 (time x 2.67 (memory x 1.15))
    or 06:32 (1.25 GB) with same HB (time x 3.20 (memory x 1.43))

@gares
Copy link
Member

gares commented Aug 18, 2023

Hum, I think accumulating the db first should actually be slower.
Ideally, if the new picky spilling code allows for it, it should be the very last thing, even after the main.

@gares
Copy link
Member

gares commented Aug 18, 2023

But for that, great work!

About eta, I really don't recall why it is there. CC @CohenCyril

@CohenCyril
Copy link
Member

CohenCyril commented Aug 18, 2023

But for that, great work!

About eta, I really don't recall why it is there. CC @CohenCyril

It's a internal way to achieve the same feature as HB.pack...

@proux01
Copy link
Contributor Author

proux01 commented Aug 18, 2023

Hum, I think accumulating the db first should actually be slower.

Well it seems to be consistently a tad faster here (like 2-3% total compil time on MathComp) but no idea why.

Ideally, if the new picky spilling code allows for it, it should be the very last thing, even after the main.

I haven't tried that, I'll do.

@proux01
Copy link
Contributor Author

proux01 commented Aug 21, 2023

So, I did try accumulating the db after main and it seems consistently 2 to 3% slower on MC2 compilation than accumulating the db first. No idea why. @gares why do you expect it to be faster?

@gares
Copy link
Member

gares commented Aug 28, 2023

I think my original reasoning was wrong, but we can still improve over your solution in two ways.

The compilation cache is simplistic in the sense that the unit composing a command/tactics are considered in linear dependency order. So when one changes all the following ones are recompiled. Still units which are DBs are shared among programs, and apparently in HB that unit is large (or better it is made of many tiny units).

If you put the DB first, then it has no dependency on other files, so every time you change it and you run a command:

  • the DB is extended (you compile the last unit which was added) and you cache it
  • all the other units of the program are recompiled and cached

So next time you run the same command (assuming it does not change the DB) the cache hits.
If you run any other command, you do the second point above, but not the first one which is the most expensive.

If you put the DB last it is considered to depend on the previous files, so if you have 2 commands accumulating the DB over a different list of base files, well, these two "copies" of the DB have different dependencies and are recompiled independently (like in git, their hash also includes the hash of their ancestors, which are different).

So one way to improve is to introduce (in elpi) the notion of unit dependency but that is not immediate.
Another way is to make all commands the same, that is accumulate all sources but for the main entry point. Then accumulate the DB. Then the main entry point (which is very small, the few lines in structure.v). This would save the recompilation of the units that in your patch follow the DB, but could be moved before it. I don't know if that would save a measurable amount of time.

@proux01 proux01 force-pushed the perf_compress_coercion branch from 1e7c435 to 16b415b Compare August 29, 2023 07:22
@proux01
Copy link
Contributor Author

proux01 commented Aug 29, 2023

So you were right, absolutely no measurable performance impact (the accumulation time is indeed vastly dominated by the DB). I pushed the code with an explanatory comment nonetheless.

@gares
Copy link
Member

gares commented Aug 29, 2023

Thanks for trying. But if in the end the time is the same, maybe it's better without the unneeded files accumulated in structure.v no? Or I misunderstood your measurement?

@proux01 proux01 force-pushed the perf_compress_coercion branch from 16b415b to dc9c6e4 Compare August 29, 2023 11:31
@proux01
Copy link
Contributor Author

proux01 commented Aug 29, 2023

You're right, done.

proux01 and others added 5 commits September 6, 2023 17:01
The compress predicate had a cubic number of entries in the size of
a hierarchy whereas sub-class is only quadratic.

Compilation of MathComp:
before: 22:57 (1.53 GB)
  HB.structure: 05:42
  HB.instance: 02:31
after: 20:36 (1.26 GB)
  HB.structure: 03:10
  HB.instance: 02:29
Compilation of MathComp:
before: 20:36 (1.26 GB)
  HB.structure: 03:10
  HB.instance: 02:29
after: 17:46 (1.24 GB)
  HB.structure: 01:37
  HB.instance: 02:18
Compilation of MathComp:
before: 17.46 (1.24 GB)
  HB.structure: 01:37
  HB.instance: 02:18
after: 17.22 (1.27 GB)
  HB.structure: 01:38
  HB.instance: 02:21
@proux01 proux01 force-pushed the perf_compress_coercion branch from dc9c6e4 to 9116e20 Compare September 6, 2023 15:01
@gares gares merged commit 4c7c83d into math-comp:master Sep 6, 2023
107 checks passed
@proux01
Copy link
Contributor Author

proux01 commented Sep 6, 2023

Thanks!

@proux01 proux01 deleted the perf_compress_coercion branch September 6, 2023 16:03
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

Successfully merging this pull request may close these issues.

3 participants