About   |   Getting Started   |   Downloads   |   Documentation   |   Forum


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A note on accessing fonts by name
04-03-2017, 11:33 AM
Post: #1
A note on accessing fonts by name
I'd like to delineate a possible performance issue with Illustrator – and ways to greatly improve the speed with hdi_core – so other developers can benefit from this as well. We had some issues with our own plugins recently, which were resolved as explained below.

When using hdi::core::Illustrator::fontWithName() or hdi::core::FontPref, especially in the context of a long loop, performance can take a serious hit. Our plugins have some instances in which we must loop over thousands of art objects and inspect some stored font data, which ultimately comes down to many calls to hdi::core::Illustrator::fontWithName(). Illustrator itself provides no direct way to acquire a font by name, so we must loop over all the fonts in order to find it. Some users have thousands of fonts, which makes the problem even worse.

To remedy this situation, hdi_core has always had hdi::core::Illustrator::cacheFonts() and hdi::core::Illustrator::clearFontCache(). This allows one to create a cached font "context", where we build a map in memory of all fonts keyed by their names. This reduces the order of complexity from O(n) to O(log n). Before e.g. starting a long loop which will acquire fonts by name, first cache all the fonts. After the loop is over, clear the font cache.

It is not worthwhile to cache fonts before every call to hdi::core::Illustrator::fontWithName() because of the overhead of creating the font cache in the first place (we must loop over all fonts exactly once to build the map). However, one cannot simply cache all the fonts when their plugin loads and clear the cache when the plugin is unloaded, because technologies like Adobe TypeKit allow fonts to be added to/removed from Illustrator at runtime.

To hammer the point home, we utilized some code profiling on customers machines to determine that certain common operations were taking several seconds to complete (for customers where lots of art and lots of fonts were involved). After adding font caching to the proper spots, we reduced the timing to mere hundredths of a second.
Find all posts by this user
Quote this message in a reply
04-04-2017, 04:01 PM
Post: #2
RE: A note on accessing fonts by name
Thanks for sharing, Garrett. Could this possibly have anything to do with the slow file-opening problems some experience when using CORE plugins while running Lotus Notes? I know you were investigating that, but this strikes me as something completely unrelated to that or to parsing art objects in general (without referencing any fonts used).
Find all posts by this user
Quote this message in a reply
04-05-2017, 09:32 AM
Post: #3
RE: A note on accessing fonts by name
I don't know about any Lotus Notes connection, but we had one user with slow file opening issues see the problem resolved when we put in additional font caching.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)