unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Reducing iconv-induced memory usage
@ 2011-04-26 21:10 Ludovic Courtès
  2011-04-26 22:41 ` Ludovic Courtès
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2011-04-26 21:10 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 725 bytes --]

Hello!

As Andy noted in the past, iconv conversion descriptors associated with
ports take up a lot of malloc’d memory, that only gets freed when
finalizers are run.  On GNU/Linux, a UTF-8 → UTF-8 C.D., which does
nothing, mallocs 180 KiB (!), according to the program attached.  So the
problem is acute.

So I think we should special-case UTF-8 I/O to not use iconv at all.

For output, it’s easy since we already do the conversion to UTF-8 in
‘display_string’.  For input, it’s a bit more work because input byte
streams have to be checked for invalid sequences.

I’m working on a patch but I’d like to get initial feedback and also
about whether it should wait until after 2.0.1 or not.

Thanks,
Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: the program --]
[-- Type: text/x-csrc, Size: 572 bytes --]

#include <iconv.h>
#include <malloc.h>

static size_t total;

static void * (*prev_hook) (size_t, const void *);

static void *
m (size_t s, const void *c)
{
  __malloc_hook = prev_hook;
  printf ("alloc %zi\n", s);
  void *r = malloc (s);
  total += s;
  __malloc_hook = &m;
  return r;
}

static void
my_init_hook (void)
{
  prev_hook = __malloc_hook;
  __malloc_hook = &m;
}

void (*__malloc_initialize_hook) (void) = my_init_hook;

int
main (int argc, char *argv[])
{
  total = 0;
  iconv_open ("UTF-8", "UTF-8");
  printf ("allocated %zi B\n", total);
  return 0;
}


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-05-07 20:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-26 21:10 Reducing iconv-induced memory usage Ludovic Courtès
2011-04-26 22:41 ` Ludovic Courtès
2011-04-27  3:47   ` Mark H Weaver
2011-04-27 14:36     ` Ludovic Courtès
2011-05-05 16:19     ` Ludovic Courtès
2011-05-06 16:19       ` Ludovic Courtès
2011-05-07 20:51         ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).