Hi,

2012/3/8 Adrien <camarade...@gmail.com>:
> Hi,
>
> On 08/03/2012, Sylvain Le Gall <sylv...@le-gall.net> wrote:
>> Hi,
>>
>> 2012/3/8 Daniel Bünzli <daniel.buen...@erratique.ch>:
>>> Le jeudi, 8 mars 2012 ŕ 09:31, Sylvain Le Gall a écrit :
>>>> setup.ml will be enough for me ;-) But I am biased.
>>>
>>> For distribution, I'm fine with that aswell. For developement setup.ml
>>> takes too much time to invoke (adds an overhead of 0.5s on my system).
>>>
>>
>> That the parsing time because the file is big. I know this issue and
>> will try to improve that in the future. I think a 50% down size is
>> possible, that will bring this time to 250ms. Although, I don't think
>> that even for development env a 500ms delay is that big... I doubt to
>> be able to reduce to ~0s.
>
> For my own stuff, I've been using a Makefile which includes a rule to
> (re)compile setup.ml into an executable with ocamlc.opt (compiling
> with ocamlopt was too slow). My usual development machine isn't
> terribly fast and this has helped a lot.
>
> I think there was a mention of an issue though but it can help a lot.

Make sense. So super quick hack!

Add at the beginning of setup.ml:

let () =
  let setup_ml = Sys.argv.(0) in
  (* Check we are running the script with ocaml, not the compiled mode *)
  if Filename.check_suffix setup_ml ".ml" then
    begin
      let setup_base = Filename.chop_extension setup_ml in
      let setup_digest = setup_base ^ ".digest" in
      let setup_exe =
        Filename.concat
          Filename.current_dir_name
          (setup_base ^ (if Sys.os_type = "Win32" then ".exe" else ""))
      in
      let self_digest =
        let chn = open_in setup_ml in
        let digest = Digest.channel chn (in_channel_length chn) in
          close_in chn;
          digest
      in
      let pre_digest =
        try
          let chn = open_in setup_digest in
          let digest = Digest.input chn in
            close_in chn;
            digest
        with _ ->
          Digest.string ""
      in
      let clean ?(all=false) () =
        List.iter
          (fun fn -> try Sys.remove fn with _ -> ())
          (
            (if all then
               [setup_exe; setup_digest]
             else
               [])
            @
            [setup_base ^ ".cmi"; setup_base ^ ".cmo"]
          )
      in
      if not (Sys.file_exists setup_exe) || self_digest <> pre_digest then
        begin
          match Sys.command "ocamlfind ocamlc -o setup setup.ml" with
            | 0 ->
                (* Compilation succeed, update the digest *)
                let chn = open_out setup_digest in
                  Digest.output chn self_digest;
                  close_out chn;
                  clean ()
            | _ ->
                prerr_endline "E: Compilation of setup.ml doesn't succeed.";
                clean ~all:true ()
        end;
      if Sys.file_exists setup_exe then
        begin
          print_endline "I: Running the compiled version of setup.ml";
          exit
            (Sys.command
               (String.concat " "
                  (List.map Filename.quote
                     (setup_exe :: (List.tl (Array.to_list Sys.argv))))))
        end
    end

Running time:
without the hack -> 500ms
with hack 1st run -> 268ms
with hack 2nd run -> 110ms

Do you think it make sense to include this at the beginning of setup.ml ?

Cheers
Sylvain


-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to