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

Reduce Internal boilerplate #2874

Merged
merged 22 commits into from
Jul 9, 2024
Merged

Reduce Internal boilerplate #2874

merged 22 commits into from
Jul 9, 2024

Conversation

janmasrovira
Copy link
Collaborator

@janmasrovira janmasrovira commented Jul 2, 2024

This pr modifies the HasExpressions class to allow traversing direct subexpressions rather than only leaf expressions. I've added the lens library as a dependency to have access to generic traversals defined in Control.Lens.Plated.

@janmasrovira janmasrovira self-assigned this Jul 2, 2024
@janmasrovira janmasrovira force-pushed the reduce-internal-boilerplate branch from 8151f1a to 67fff1e Compare July 3, 2024 23:16
@janmasrovira janmasrovira force-pushed the reduce-internal-boilerplate branch from 67fff1e to bfd9e15 Compare July 3, 2024 23:19
@lukaszcz
Copy link
Collaborator

lukaszcz commented Jul 4, 2024

This PR switches to a different lens library and uses more general library functions to implement some traversals over program representation. I think once it's done we should benchmark it to have an idea how this affects performance.

@janmasrovira janmasrovira force-pushed the reduce-internal-boilerplate branch from 2006557 to 48a0157 Compare July 4, 2024 10:37
@janmasrovira janmasrovira force-pushed the reduce-internal-boilerplate branch from 3da04b1 to f2ed27b Compare July 4, 2024 10:56
@janmasrovira
Copy link
Collaborator Author

This PR switches to a different lens library and uses more general library functions to implement some traversals over program representation. I think once it's done we should benchmark it to have an idea how this affects performance.

afaik the implementation is equivalent so performance should be the same. It's just that lens is a bigger library.
I've run the benchmark on the stdlib and it seems to indicate that.

hyperfine --warmup 1 --prepare 'juvix clean' 'juvix typecheck index.juvix' 'juvix-main typecheck index.juvix' Benchmark 1: juvix typecheck index.juvix
  Time (mean ± σ):     436.9 ms ±   7.3 ms    [User: 874.8 ms, System: 103.0 ms]
  Range (min … max):   427.7 ms … 447.0 ms    10 runs

Benchmark 2: juvix-main typecheck index.juvix
  Time (mean ± σ):     438.6 ms ±   7.0 ms    [User: 883.1 ms, System: 88.4 ms]
  Range (min … max):   426.2 ms … 447.9 ms    10 runs

Summary
  juvix typecheck index.juvix ran
    1.00 ± 0.02 times faster than juvix-main typecheck index.juvix

I included the lens library because it has the functions that I needed and it was easier for me this way. Then we have two options, we use lens from now on, or we copy to our codebase the (relatively small) fragment that we need for this pr. That's something that we can discuss on a call next week.

@paulcadman
Copy link
Collaborator

I included the lens library because it has the functions that I needed and it was easier for me this way. Then we have two options, we use lens from now on, or we copy to our codebase the (relatively small) fragment that we need for this pr. That's something that we can discuss on a call next week.

There's microlens-pro that provides Prisms / Isos if that's what you need. (this is not an endorsement).

@lukaszcz
Copy link
Collaborator

lukaszcz commented Jul 4, 2024

afaik the implementation is equivalent so performance should be the same. It's just that lens is a bigger library. I've run the benchmark on the stdlib and it seems to indicate that.

It's good it doesn't matter, but such things can give you nasty surprises, like with this uniplate thing. Because someone might've implemented some accessor the wrong way, which is say 10x times slower, which makes the whole program say 2x slower because it's used all over the place.

But fortunately no nasty surprises here.

@janmasrovira janmasrovira marked this pull request as ready for review July 8, 2024 09:54
@janmasrovira janmasrovira merged commit 840b7e9 into main Jul 9, 2024
8 checks passed
@janmasrovira janmasrovira deleted the reduce-internal-boilerplate branch July 9, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants