caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin.jambon@ens-lyon.org>
To: caml-list@inria.fr
Subject: Re: AW: [Caml-list] Behaviour of an OCaml program: any possible GC improvement?
Date: Wed, 24 Oct 2012 10:23:16 -0700	[thread overview]
Message-ID: <50882404.2030106@ens-lyon.org> (raw)
In-Reply-To: <1351094857.12207.12@samsung>

On 10/24/2012 09:07 AM, Gerd Stolpmann wrote:
> I don't think you can do much here by just setting parameters. (Btw.,
> there is no need to compile the mli's with -p.)
>
> I've seen high CPU for garbage collection frequently for mainly
> functional programs. It's their nature - you generate lots of
> short-living intermediate results. You can change that only by changing
> the algorithm, e.g. by caching results that would otherwise be
> recomputed again. Some improvement is also possible with simple tricks,
> e.g. if you have something like
>
> Number 0
>
> where Number is from an algebraic type, and you use this term
> frequently, consider to add a constant for it,
>
> let n0 = Number 0
>
> so this isn't reallocated all the time (even: if n=0 then n0 else Number
> n). If this term is used often, this makes a noticeable difference.

Note that the following works too:

   if n = 0 then Number 0  (* structured constant *)
   else Number n


# type t = Number of int;;
type t = Number of int
# let f () = Number 0;;
val f : unit -> t = <fun>
# f () == f ();;
- : bool = true


Martin


> Am 24.10.2012 17:09:12 schrieb(en) David MENTRE:
>> Hello,
>>
>> 2012/10/24 David MENTRE <dmentre@linux-france.org>:
>> > But, after recompiling everything from scratch and redoing my tests
>> > (taking care of erasing old gmon.out file), I have the same result
>> > (with <spontaneous> calling caml_call_gc). :-(
>>
>> For the sake of completeness, I installed latest OCaml 4.00.1 (for the
>> recall, Linux x86_64 platform), recompiled everything from scratch and
>> re-did my tests. I obtain roughly the same results and the same
>> <spontaneous> calling caml_call_gc. :-(
>>
>> There should be something obvious that I missed.
>>
>> """
>> Flat profile:
>>
>> Each sample counts as 0.01 seconds.
>>   %   cumulative   self              self     total
>>  time   seconds   seconds    calls   s/call   s/call  name
>>  32.54    155.97   155.97    35791     0.00     0.01  mark_slice
>>  19.87    251.24    95.26    58230     0.00     0.00  sweep_slice
>>  12.35    310.42    59.18    88113     0.00     0.00  camlMap__map_1150
>>   6.66    342.34    31.92    94021     0.00     0.00  caml_oldify_mopup
>>   6.57    373.81    31.47 1986040761     0.00     0.00
>> caml_page_table_lookup
>>   4.66    396.17    22.36 3792214394     0.00     0.00  caml_fl_allocate
>>   4.33    416.94    20.77 3799622226     0.00     0.00  caml_oldify_one
>>   3.39    433.18    16.24 3873315118     0.00     0.00
>> caml_fl_merge_block
>>   2.51    445.20    12.03 3792214239     0.00     0.00  caml_alloc_shr
>>   1.38    451.83     6.63 3882908903     0.00     0.00
>> camlData_typing__apply_1255
>>   1.26    457.88     6.05 3792214239     0.00     0.00  allocate_block
>>   1.20    463.62     5.74        1     5.74     5.74
>> caml_realloc_ref_table
>>   0.49    465.99     2.37   188042     0.00     0.00  clear_table
>>   0.44    468.09     2.10 3881730105     0.00     0.00
>> camlData_typing__fun_1445
>>   0.42    470.08     1.99                             caml_fl_reset
>>   0.31    471.57     1.50
>> caml_set_allocation_policy
>>   0.28    472.90     1.33   896098     0.00     0.00  caml_gc_message
>>   0.24    474.06     1.16       74     0.02     0.02  camlMap__iter_1144
>>   0.22    475.12     1.06      155     0.01     0.01  caml_add_to_heap
>>   0.11    475.64     0.53
>> camlData_typing__fun_1430
>>   0.07    475.98     0.34
>> camlData_typing__print_vset_1115
>>   0.06    476.29     0.31    94021     0.00     0.00
>> caml_oldify_local_roots
>>   0.04    476.46     0.17 10355866     0.00     0.00
>> camlFormat__doprn_1525
>>   0.03    476.61     0.15 95566109     0.00     0.00  caml_modify
>>   0.03    476.74     0.13  5946696     0.00     0.00
>> camlFormat__kpr_1514
>>   0.03    476.86     0.12 10179867     0.00     0.00
>> camlFormat__advance_loop_1173
>>   0.02    476.97     0.11 16452591     0.00     0.00
>> camlFormat__format_pp_token_1134
>>   0.02    477.05     0.08 15459066     0.00     0.00  caml_putblock
>>   0.02    477.13     0.08 16452612     0.00     0.00
>> camlFormat__add_queue_1087
>> [...]
>> granularity: each sample hit covers 2 byte(s) for 0.00% of 479.32 seconds
>>
>> index % time    self  children    called     name
>>                 0.00    0.11      25/94021       caml_alloc_small [75]
>>                 0.00    0.56     133/94021       caml_alloc_string [51]
>>                 0.02  394.48   93863/94021
>> caml_garbage_collection [3]
>> [1]     82.4    0.02  395.15   94021         caml_minor_collection [1]
>>                 0.02  297.93   94021/94021
>> caml_major_collection_slice [4]
>>                 0.01   97.19  188042/188042      caml_empty_minor_heap
>> [7]
>>                 0.00    0.00   94021/94021       caml_final_do_calls
>> [353]
>> -----------------------------------------------
>>                                                  <spontaneous>
>> [2]     82.3    0.04  394.50                 caml_call_gc [2]
>>                 0.00  394.50   93863/93863
>> caml_garbage_collection [3]
>> -----------------------------------------------
>>                 0.00  394.50   93863/93863       caml_call_gc [2]
>> [3]     82.3    0.00  394.50   93863         caml_garbage_collection [3]
>>                 0.02  394.48   93863/94021       caml_minor_collection
>> [1]
>>                 0.00    0.00   93863/97401
>> caml_process_pending_signals [352]
>> -----------------------------------------------
>>                 0.02  297.93   94021/94021       caml_minor_collection
>> [1]
>> [4]     62.2    0.02  297.93   94021
>> caml_major_collection_slice [4]
>>               155.97   29.41   35791/35791       mark_slice [5]
>>                95.26   16.33   58230/58230       sweep_slice [6]
>>                 0.84    0.00  564126/896098      caml_gc_message [43]
>>                 0.00    0.10    4652/4652        start_cycle [76]
>>                 0.00    0.01    4651/4651
>> caml_compact_heap_maybe [135]
>> -----------------------------------------------
>>               155.97   29.41   35791/35791
>> caml_major_collection_slice [4]
>> [5]     38.7  155.97   29.41   35791         mark_slice [5]
>>                29.31    0.00 1849494323/1986040761
>> caml_page_table_lookup [16]
>>                 0.11    0.00   71582/896098      caml_gc_message [43]
>>                 0.00    0.00       1/1           realloc_gray_vals [269]
>>                 0.00    0.00    4652/4652        caml_final_update [377]
>>                 0.00    0.00    4652/4653        caml_fl_init_merge [375]
>> -----------------------------------------------
>>                95.26   16.33   58230/58230
>> caml_major_collection_slice [4]
>> [6]     23.3   95.26   16.33   58230         sweep_slice [6]
>>                16.24    0.00 3873315117/3873315118
>> caml_fl_merge_block [18]
>>                 0.09    0.00   58230/896098      caml_gc_message [43]
>>                 0.00    0.00       1/1           caml_finalize_channel
>> [477]
>> -----------------------------------------------
>>                 0.01   97.19  188042/188042      caml_minor_collection
>> [1]
>> [7]     20.3    0.01   97.19  188042         caml_empty_minor_heap [7]
>>                31.92   62.08   94021/94021       caml_oldify_mopup [8]
>>                 2.37    0.00  188042/188042      clear_table [29]
>>                 0.31    0.07   94021/94021
>> caml_oldify_local_roots [58]
>>                 0.28    0.00  188042/896098      caml_gc_message [43]
>>                 0.05    0.10 9383144/3799622226     caml_oldify_one [14]
>>                 0.00    0.00  188042/188042
>> caml_final_empty_young [344]
>> -----------------------------------------------
>>                31.92   62.08   94021/94021       caml_empty_minor_heap
>> [7]
>> [8]     19.6   31.92   62.08   94021         caml_oldify_mopup [8]
>>                20.71   41.37 3787931806/3799622226     caml_oldify_one
>> [14]
>> -----------------------------------------------
>> [...]
>> """
>>
>> Best regards,
>> david
>>
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>
>>
>


  reply	other threads:[~2012-10-24 17:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-24 10:08 David MENTRE
2012-10-24 10:33 ` John Whitington
2012-10-24 12:30   ` David MENTRE
2012-10-24 12:39     ` John Whitington
2012-10-24 12:45       ` Edgar Friendly
2012-10-24 12:53         ` John Whitington
2012-10-24 13:19       ` David MENTRE
2012-10-24 13:27         ` John Whitington
2012-10-24 13:38         ` Oliver Bandel
2012-10-24 14:30           ` David MENTRE
2012-10-24 15:09             ` David MENTRE
2012-10-24 16:07               ` AW: " Gerd Stolpmann
2012-10-24 17:23                 ` Martin Jambon [this message]
     [not found]               ` <1351094817.12207.11@samsung>
2012-10-25  6:48                 ` David MENTRE
2012-10-25  7:37                   ` David House
2012-10-24 10:38 ` Török Edwin
2012-10-25 10:06   ` David MENTRE
2012-10-25 10:16     ` Török Edwin
2012-10-25 10:19       ` David MENTRE
2012-11-07 11:52     ` David MENTRE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50882404.2030106@ens-lyon.org \
    --to=martin.jambon@ens-lyon.org \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).