{"id":964,"date":"2010-05-07T11:37:28","date_gmt":"2010-05-07T11:37:28","guid":{"rendered":"http:\/\/www.navision-blog.de\/2010\/05\/07\/using-a-mailboxprocessor-to-speedup-fake-f-make\/"},"modified":"2022-12-29T12:37:39","modified_gmt":"2022-12-29T12:37:39","slug":"using-a-mailboxprocessor-to-speedup-fake-f-make","status":"publish","type":"post","link":"http:\/\/www.navision-blog.de\/blog\/2010\/05\/07\/using-a-mailboxprocessor-to-speedup-fake-f-make\/","title":{"rendered":"Using a MailboxProcessor to speedup &ldquo;FAKE &ndash; F# MAKE&rdquo;"},"content":{"rendered":"<p>Earlier today I released <a href=\"http:\/\/bitbucket.org\/forki\/fake\/downloads\">\u201cFAKE \u2013 F# Make\u201d version 1.10.0<\/a>. This new release contains a lot path issue fixes for <a href=\"http:\/\/www.mono-project.com\/Main_Page\">Mono<\/a> and a new architecture for logging and tracing. <\/p>\n<p>A guy named Joel Mueller had an awesome idea and sent me some patches. He noticed that TraceHelper.fs writes all messages synchronously to the console and\/or a XML output file, which means the actual build operations must wait on the writing of hundreds of trace messages, slowing down the actual build.<\/p>\n<p>His idea was to use a MailboxProcessor to buffer up the trace messages and write them out asynchronously, so that the actual build can proceed at full speed.<\/p>\n<div style=\"font-family: courier new; background: white; color: black; font-size: 10pt\">\n<p style=\"margin: 0px\"><span style=\"color: blue\">type<\/span> Message = <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160; { Text&#160;&#160;&#160;&#160;&#160; : string<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160; Color&#160;&#160;&#160;&#160; : ConsoleColor<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160; Newline&#160;&#160; : bool<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160; Important : bool}<\/p>\n<p style=\"margin: 0px\">&#160;<\/p>\n<p style=\"margin: 0px\"><span style=\"color: green\">\/\/\/ &#8230;.<\/span><\/p>\n<p style=\"margin: 0px\">&#160;<\/p>\n<p style=\"margin: 0px\"><span style=\"color: blue\">let<\/span> buffer = MailboxProcessor.Start (<span style=\"color: blue\">fun<\/span> inbox <span style=\"color: blue\">-&gt;<\/span><\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160; <span style=\"color: blue\">let<\/span> <span style=\"color: blue\">rec<\/span> loop () = <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; async {<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style=\"color: blue\">let!<\/span> (msg:Message) = inbox.Receive()<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style=\"color: blue\">match<\/span> traceMode <span style=\"color: blue\">with<\/span><\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; | Console <span style=\"color: blue\">-&gt;<\/span> logMessageToConsole msg<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; | Xml&#160;&#160;&#160;&#160; <span style=\"color: blue\">-&gt;<\/span> appendXML msg.Text<\/p>\n<p style=\"margin: 0px\">&#160;<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style=\"color: blue\">return!<\/span> loop ()}<\/p>\n<p style=\"margin: 0px\">&#160;<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160; loop ())&#160;&#160;&#160;&#160;&#160; <\/p>\n<\/p>\n<\/div>\n<p>Now all internal logging and tracing functions can post their their messages to the inbox of the MailboxProcessor:<\/p>\n<div style=\"font-family: courier new; background: white; color: black; font-size: 10pt\">\n<p style=\"margin: 0px\"><span style=\"color: green\">\/\/\/ Logs the specified string (via message buffer)<\/span><\/p>\n<p style=\"margin: 0px\"><span style=\"color: blue\">let<\/span> logMessage important newLine message =<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160; <span style=\"color: blue\">match<\/span> traceMode <span style=\"color: blue\">with<\/span><\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160; | Console <span style=\"color: blue\">-&gt;<\/span><\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; { Text = message; <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Important = important; <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Newline = newLine; <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Color = ConsoleColor.White }<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |&gt; buffer.Post<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160; | Xml&#160;&#160;&#160;&#160; <span style=\"color: blue\">-&gt;<\/span> <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; { defaultMessage <span style=\"color: blue\">with<\/span> <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Text = sprintf <span style=\"color: maroon\">&quot;&lt;message&gt;&lt;![CDATA[%s]]&gt;&lt;\/message&gt;&quot;<\/span> <\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; message }<\/p>\n<p style=\"margin: 0px\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; |&gt; buffer.Post <\/p>\n<\/p>\n<\/div>\n<p>This idea reduces the build time of FAKE\u2019s self build from 3 min. to 2 min. Which is really amazing, since I didn\u2019t have to change anything in the build script. This version is compatible to the last released version.<\/p>\n<p>Please download <a href=\"http:\/\/bitbucket.org\/forki\/fake\/downloads\">\u201cFAKE \u2013 F# Make\u201d version 1.10.0<\/a> and tell me what you think.<\/p>\n<div style=\"font-size:0px;\"><a href=\"https:\/\/edpillgrece.gr\">https:\/\/edpillgrece.gr<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Earlier today I released \u201cFAKE \u2013 F# Make\u201d version 1.10.0. This new release contains a lot path issue fixes for Mono and a new architecture for logging and tracing. A guy named Joel Mueller had an awesome idea and sent me some patches. He noticed that TraceHelper.fs writes all messages synchronously to the console and\/or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[448,546],"tags":[664,545,544,149],"_links":{"self":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/964"}],"collection":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/comments?post=964"}],"version-history":[{"count":1,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/964\/revisions"}],"predecessor-version":[{"id":2037,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/964\/revisions\/2037"}],"wp:attachment":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/media?parent=964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/categories?post=964"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/tags?post=964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}