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

Optimize letFunctionDefs in Juvix.Compiler.Internal.Data.InfoTable #2867

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

lukaszcz
Copy link
Collaborator

@lukaszcz lukaszcz commented Jun 28, 2024

Benchmark results

Using Uniplate:

heliax@imac bench % hyperfine --prepare 'juvix clean --global' -w 1 'juvix typecheck bench.juvix -N 1'
Benchmark 1: juvix typecheck bench.juvix -N 1
  Time (mean ± σ):      1.399 s ±  0.023 s    [User: 1.346 s, System: 0.041 s]
  Range (min … max):    1.374 s …  1.452 s    10 runs

Using HasLetDefs:

heliax@imac bench % hyperfine --prepare 'juvix clean --global' -w 1 'juvix typecheck bench.juvix -N 1'
Benchmark 1: juvix typecheck bench.juvix -N 1
  Time (mean ± σ):      1.098 s ±  0.015 s    [User: 1.047 s, System: 0.040 s]
  Range (min … max):    1.074 s …  1.120 s    10 runs

So it's roughly 1.1s vs. 1.4s, faster by 0.2s. About 14% improvement.

The benchmark file just imports the standard library:

module bench;

import Stdlib.Prelude open;

main : Nat := 0;

Both juvix binaries were compiled with optimizations, using just install.

@lukaszcz lukaszcz added this to the 0.6.3 milestone Jun 28, 2024
@lukaszcz lukaszcz self-assigned this Jun 28, 2024
@lukaszcz
Copy link
Collaborator Author

lukaszcz commented Jun 28, 2024

I think the conclusion from this is that we should never use automatically generated Uniplate instances to traverse the whole program tree or anything sizeable. The performance penalty is ridiculous -- we were traversing only twice to get all lets (once before and once after type checking) and this alone took above 14% of total running time.

Copy link
Collaborator

@janmasrovira janmasrovira left a comment

Choose a reason for hiding this comment

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

wow

@lukaszcz lukaszcz merged commit fef37a8 into main Jun 28, 2024
4 checks passed
@lukaszcz lukaszcz deleted the fix-uniplate branch June 28, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve efficiency of building Internal.InfoTable
2 participants