After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 69152 - PATCH: make g_convert cache iconv descriptors
PATCH: make g_convert cache iconv descriptors
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
1.3.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2002-01-20 01:13 UTC by Jeffrey Stedfast
Modified: 2011-02-18 15:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gconvert.patch (11.23 KB, patch)
2002-01-20 01:14 UTC, Jeffrey Stedfast
none Details | Review
updated to apply cleanly to latest cvs (after fix for bug #69153 was applied) (11.18 KB, patch)
2002-01-21 21:08 UTC, Jeffrey Stedfast
none Details | Review
new proposed patch (8.60 KB, patch)
2002-01-25 00:46 UTC, Jeffrey Stedfast
none Details | Review

Description Jeffrey Stedfast 2002-01-20 01:13:34 UTC
On systems like Solaris (and even Linux?), iconv_open() can be fairly slow
if due to having to dlopen a module for each charset involved in the
conversion.

The attached patch is an attempt at minimizing the overhead of iconv_open
by caching iconv descriptors.


In writing this patch I discovered a bug (for which I will make a separate
bug report in a few moments) that didn't close an opened converter in
g_convert_with_fallback() when the code fails to get utf8 text. The
attached patch also fixes that...
Comment 1 Jeffrey Stedfast 2002-01-20 01:14:15 UTC
Created attachment 6449 [details] [review]
gconvert.patch
Comment 2 Jeffrey Stedfast 2002-01-21 21:08:02 UTC
Created attachment 6465 [details] [review]
updated to apply cleanly to latest cvs (after fix for bug #69153 was applied)
Comment 3 Owen Taylor 2002-01-22 00:41:34 UTC
This is very nice code, and looks like it should do the job
well.

Still, I can't help but thinking that it is just a bit
over-engineered... it's a fair chunk of code.
The one suggestion I would make for simplification, is
that I think we can assume:

 "If one converter for a encoding pair is loaded, it will
  be cheap to load a second one"

With that in mind, I don't think it would hurt to remove
the code handling multiple open converters for the same
key.

Other comments:

 - I'd ditch the g_atexit() cleanup handler or at least
   #ifdef it out. atexit() handlers are a scarce resource
   on some systems, and if we don't do this anywhere
   else in GLib, I don't see a point in doing it here.
   (ref. my well-known bias about proper memory leak debugging 
   techniques ;-)

 - If written from scratch, I'd prefer to see the code
   use the GLib data structures ... GList and GQeuue;
   the cache isn't big enough to make the overhead
   of separate list nodes / structures important.
   It's probably not worth reworking at this point.
Comment 4 Jeffrey Stedfast 2002-01-25 00:44:51 UTC
Okay, I've had another go at it. This time we only ever cache a single
iconv_t descriptor for any conversion type. I've also modified the
code to use GList rather than generic list.

also, I found several bugs in the last patch so if it is decided that
you prefer the old code, let me know and I'll post the fixed up
version of that.
Comment 5 Jeffrey Stedfast 2002-01-25 00:46:43 UTC
Created attachment 6512 [details] [review]
new proposed patch
Comment 6 Owen Taylor 2002-01-28 23:04:12 UTC
Looks fine, please commit.
Comment 7 Jeffrey Stedfast 2002-01-29 18:48:25 UTC
just committed to cvs.