{"id":5770,"date":"2016-07-11T14:55:24","date_gmt":"2016-07-11T19:55:24","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=5770"},"modified":"2016-07-11T14:55:24","modified_gmt":"2016-07-11T19:55:24","slug":"tips-for-dealing-with-libraries","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2016\/07\/11\/tips-for-dealing-with-libraries\/","title":{"rendered":"Tips for dealing with Libraries"},"content":{"rendered":"<p>Today I will share a simple trick that might save you some time if you are dealing with large Simulink models <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/model-architecture-guidelines.html#bs8xh1u-6\">componentized using libraries<\/a>.<\/p>\n<p><strong>Long Time to Save<\/strong><\/p>\n<p>Earlier this week, I received a large model made of multiple subsystems stored in a library file. I had to do some modifications to the library. When I was done with my modifications, I clicked on the <strong>Save<\/strong> button, it took significantly longer than I expected, more than a minute.<\/p>\n<p>Curious, I decided to profile the saving operation to try understanding what was happening:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/profilerSlow.png\" alt=\"Starting the MATLAB Profiler\" \/><\/p>\n<p>Here are the results:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/profilerResults.png\" alt=\"Profiler results\" \/><\/p>\n<p><strong>The Explanation<\/strong><\/p>\n<p>When I saw that most of the time was spent in a function called \"generateSVG\", I knew exactly what was happening.<\/p>\n<p>As described in the documentation page <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/adding-libraries-to-the-library-browser.html\">Add Libraries to the Library Browser<\/a>, if you want your library file to appear in the Simulink Library Browser, you need to enable the <tt>EnableLBRepository<\/tt> property of the library.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/enableRepo.png\" alt=\"Enabling Library Browser Repository\" \/><\/p>\n<p>When this option is enabled, Simulink will save an image file for each block to be displayed in the Library Browser. This image is in <a href=\"https:\/\/en.wikipedia.org\/wiki\/Scalable_Vector_Graphics\">scalable vector graphics<\/a> format (SVG). You do not see those image files, but they are inside the SLX library file. As far as I understand, this is done to speed up the opening of the Library Browser.<\/p>\n<p>Sure enough, disabling this option made the time to save the library pass from over a minute to just a few seconds.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/disabledLBRep.png\" alt=\"Disabled Library Browser Repository\" \/><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Based on that, I recommend turning this flag on or off depending on your workflow. When you are in editing mode and you modify and save the library often, disable <tt>EnableLBRepository<\/tt>. When your library is ready to be released and deployed to other users who will access it from the Library Browser, enable <tt>EnableLBRepository<\/tt>.<\/p>\n<p><strong>A few more tips...<\/strong><\/p>\n<p>While we are talking about speeding up workflows, here is another trick I like. In my <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/startup.html\"><tt>startup.m<\/tt><\/a>, I like to add the following two lines:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/otherTrick.png\" alt=\"Speeding load\" \/><\/p>\n<p>By default, Simulink and the Library Browser are loaded in memory only the first time you simulate or open a model. Since I always use Simulink, I prefer having the loading done as soon as MATLAB launches.<\/p>\n<p><strong>Now it's your turn<\/strong><\/p>\n<p>Do you have other tips or tricks like those? Share them with us by leaving a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/otherTrick.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>Today I will share a simple trick that might save you some time if you are dealing with large Simulink models componentized using libraries.<br \/>\nLong Time to Save<br \/>\nEarlier this week, I received a large... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2016\/07\/11\/tips-for-dealing-with-libraries\/\">read more >><\/a><\/p>\n","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[33],"tags":[476,9],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5770"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=5770"}],"version-history":[{"count":11,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5770\/revisions"}],"predecessor-version":[{"id":5789,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5770\/revisions\/5789"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=5770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=5770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=5770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}