Bug 6508 - FcSortWalk() is inefficient when the arg trim is FcFalse
Summary: FcSortWalk() is inefficient when the arg trim is FcFalse
Status: VERIFIED FIXED
Alias: None
Product: fontconfig
Classification: Unclassified
Component: library (show other bugs)
Version: 2.3
Hardware: All All
: high normal
Assignee: Patrick Lam
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-06 22:21 UTC by Kenichi Handa
Modified: 2006-04-14 07:49 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Don't copy FcCharSet if we're going to chuck it anyway. (2.46 KB, patch)
2006-04-12 16:05 UTC, Patrick Lam
Details | Splinter Review

Description Kenichi Handa 2006-04-06 22:21:27 UTC
This is not a bug report but a suggestion for improvement.

FcSortWalk() does unnecessary check of charset even if called with trim==FcFlase.
I think it should have one more arg "FcBool check_cs", and build up charset only
when trim==FcTrue || check_cs==FcTrue.  And FcFontSetSort() should call it with
check_cs==FcTrue only when csp!=NULL.
Comment 1 Patrick Lam 2006-04-12 16:05:50 UTC
Created attachment 5272 [details] [review]
Don't copy FcCharSet if we're going to chuck it anyway.

This is just a bit tricky, so I'm sleeping on this patch before committing it.
Comment 2 Patrick Lam 2006-04-13 00:36:17 UTC
Good thing I slept on it, I had an extra ! in there...

Copying a charset is cheap, but doing charset union is potentially expensive. 
Not sure how much we save here.  Anyway, I've committed the fixed patch.
Comment 3 Kenichi Handa 2006-04-14 14:59:16 UTC
Thank you for the fix.  Previously, FcFontSort without trimming was more than 10
times slower than with trimming.  But now they run in almost the same speed.  It
seems that the overhead of building big fontset is compatible with the overhead
of many charset union.

This is the program I used for confirming it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fontconfig/fontconfig.h>

int
main (int argc, char **argv)
{
  int i;
  FcPattern *pat;
  FcFontSet *fs;
  FcResult result;
  FcBool trim;

  FcInit ();
  pat = FcPatternCreate ();
  FcPatternAddInteger (pat, FC_WEIGHT, FC_WEIGHT_MEDIUM);
  FcPatternAddInteger (pat, FC_SLANT, FC_SLANT_ROMAN);
  FcPatternAddInteger (pat, FC_WIDTH, FC_WIDTH_NORMAL);

  trim = (argc > 1 && strcmp (argv[1], "trim") == 0) ? FcTrue : FcFalse;
  for (i = 0; i < 10; i++)
    {
      fs = FcFontSort (NULL, pat, trim, NULL, &result);
      FcFontSetDestroy (fs);
    }
  exit (0);
}
Comment 4 Patrick Lam 2006-04-15 00:49:40 UTC
Thanks!


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.