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

Obj.reachable_words is extremely slow when called multiple times #10730

Closed
ygrek opened this issue Oct 26, 2021 · 0 comments · Fixed by #10731
Closed

Obj.reachable_words is extremely slow when called multiple times #10730

ygrek opened this issue Oct 26, 2021 · 0 comments · Fixed by #10731
Assignees

Comments

@ygrek
Copy link
Contributor

ygrek commented Oct 26, 2021

The reason seems to be that obj_counter is never reset to zero, so extern_resize_position_table is called on every invocation.

Here is a dirty proof (another way to observe is to run similar program and put breakpoint on extern_resize_position_table):

$ ocamlopt q_stubs.c q.ml -o q
$ ./q
0) obj_counter 111 reachable_words 333
1) obj_counter 222 reachable_words 333
2) obj_counter 333 reachable_words 333
3) obj_counter 444 reachable_words 333
4) obj_counter 555 reachable_words 333
5) obj_counter 666 reachable_words 333
6) obj_counter 777 reachable_words 333
7) obj_counter 888 reachable_words 333
8) obj_counter 999 reachable_words 333
9) obj_counter 1110 reachable_words 333
$ cat q.ml 
external obj_counter : unit -> int = "ml_obj_counter"
let () =
  let a = Array.init 10 (fun _ -> List.init 111 (fun _ -> 'a')) in
  Array.iteri (fun i l -> Printf.printf "%d) obj_counter %d reachable_words %d\n%!" i (obj_counter ()) (Obj.reachable_words @@ Obj.repr l)) a
$ cat q_stubs.c 
#include "caml/memory.h"
uintnat reference;
value ml_obj_counter(value v) {
  return Val_int(*(uintnat *)((char *)&reference - 0xc0928 + 0xbc178));
}

magic numbers are addresses of reference and obj_counter as shown by nm - quick way to access obj_counter w/o rebuilding ocaml

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 a pull request may close this issue.

2 participants