-
Notifications
You must be signed in to change notification settings - Fork 412
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
refactor: re-implement [Appendable_list] #9050
Conversation
10bce9c
to
661c67d
Compare
84cace8
to
8bdb985
Compare
Looks good to me. I'm not suggesting we put it in this PR, but I'm curious if providing built-in iteration functions for |
Actually, it occurs to me that we can reduce allocation in let to_list_rev =
let rec loop1 acc t stack =
match t with
| Empty -> loop0 acc stack
| Singleton x -> loop0 (x :: acc) stack
| Cons (x, xs) -> loop1 (x :: acc) xs stack
| List xs -> loop0 (List.rev_append xs acc) stack
| Append (xs, ys) -> loop1 acc xs (ys :: stack)
| Concat [] -> loop0 acc stack
| Concat (x :: xs) -> loop1 acc x (Concat xs :: stack)
and loop0 acc stack =
match stack with
| [] -> acc
| t :: stack -> loop1 acc t stack
in
fun t -> loop1 [] t []
;; |
One issue that makes this idea less attractive is that we are specifically converting this into a list because the list is a better representation for memoization (uses less space, easy to compare/hash). |
8bdb985
to
7efbd42
Compare
Thanks. I applied this patch. |
@pmwhite @snowleopard let me know once this is benchmarked internally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should disentangle the changes to the Appendable_list
implementation from the rest of the refactoring, to make it easier to benchmark.
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
7efbd42
to
d2206f1
Compare
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I think this one is good to go, though I don't know how our internal benchmarking went.
OK, I got some benchmark results for this PR applied internally: it's a consistent but small improvement (0.3-0.4% time, 0.1% memory). Let's merge it. @pmwhite I'm assuming you're going to import it as part of your feature. (Though it's easy for me to do too since I've got a feature ready.) |
This is the same as #9033 without any additional book-keeping for empty checks or using the most compact constructors. Performance is looking better now.