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

PR#6217 Improve perf. of functional record update #538

Merged
merged 3 commits into from Jun 26, 2016

Conversation

OlivierNicole
Copy link
Contributor

See Mantis issue #6217. Benchmarking with Core_bench on a 2.5 GHz 64-bit Intel i5-2450M showed that fieldwise copy is always faster while the number of fields is smaller than Max_young_wosize (that is, 256); beyond that point the "duplication and modification" method becomes much faster.

Benchmark details:
rfu_benchmarks.pdf
CSV results:
rfu_bench.zip

@@ -1235,7 +1235,8 @@ and transl_setinstvar self var expr =
and transl_record env all_labels repres lbl_expr_list opt_init_expr =
let size = Array.length all_labels in
(* Determine if there are "enough" new fields *)
if 3 + 2 * List.length lbl_expr_list >= size
let no_init = match opt_init_expr with None -> true | _ -> false in
if no_init || size > 255
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be Config.max_young_wosize rather than "255"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, thank you.

@damiendoligez damiendoligez added this to the 4.04 milestone Apr 11, 2016
@yminsky
Copy link

yminsky commented Apr 13, 2016

I'd be interested in seeing the benchmarks, if that's possible. Perhaps just attach the benchmark details to the PR?

@OlivierNicole
Copy link
Contributor Author

Hello,
I just attached a PDF with details and graphs.

@gasche gasche merged commit b3216f0 into ocaml:trunk Jun 26, 2016
@gasche
Copy link
Member

gasche commented Jun 26, 2016

Thanks for the detailed measurements. I merged the pull request in trunk.

(* Determine if there are "enough" fields (only relevant if this is a
functional-style record update *)
let no_init = match opt_init_expr with None -> true | _ -> false in
if no_init || size >= Config.max_young_wosize
Copy link
Contributor

Choose a reason for hiding this comment

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

The direction of this test is wrong: should be size <= Config.max_young_wosize

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops… sorry about that. Should I make a new pull request?

I believe "<" would be better since the caml_modify method is already faster with a 256 fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

A fix is part of #516

Copy link
Member

Choose a reason for hiding this comment

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

@chambart good catch! Sorry, I did review this but these conditions are trick.

I pushed a fix in 7554273 , I think it's better to separate concerns and leave your own PR about one thing.

Copy link
Member

Choose a reason for hiding this comment

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

this will cause code bloat in pathological cases

Copy link
Contributor

Choose a reason for hiding this comment

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

What cases do you have in mind? If the size is of the record is larger than 256 then it uses the "duplicate and modify" approach which requires less code.

gasche referenced this pull request Nov 4, 2016
camlspotter pushed a commit to camlspotter/ocaml that referenced this pull request Oct 17, 2017
PR#6217 Improve perf. of functional record update
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Co-authored-by: Thibaut Mattio <thibaut.mattio@gmail.com>
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.

None yet

8 participants