Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch for ocaml 3.08.3: inefficiency in channel close (linear search thru channel list) #3727

Closed
vicuna opened this issue Jul 17, 2005 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Jul 17, 2005

Original bug ID: 3727
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hi,

I found that when I used camlzip's "minizip" to unpack an archive, it
was muuuch slower than "unzip". It turned out that this was due to
a linear search in unlinking channels from the global list.

By adding a "prev" pointer, I got the speed of minizip down to the speed
of "unzip".

--chet--


--- io.c.1 2004-01-08 17:28:48.000000000 -0500
+++ io.c 2005-07-15 13:40:29.000000000 -0400
@@ -15,6 +15,7 @@

/* Buffered input/output. */

+#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -70,6 +71,9 @@
channel->old_revealed = 0;
channel->refcount = 0;
channel->next = caml_all_opened_channels;

  • channel->prev = NULL;
  • if (NULL != caml_all_opened_channels)
  • caml_all_opened_channels->prev = channel;
    caml_all_opened_channels = channel;
    return channel;
    }
    @@ -84,14 +88,30 @@
    }

static void unlink_channel(struct channel *channel)
+#if 1
+{

  • Assert (caml_all_opened_channels);

  • if (NULL == channel->prev) {

  • Assert (channel == caml_all_opened_channels);

  • caml_all_opened_channels = caml_all_opened_channels->next;

  • if (caml_all_opened_channels) caml_all_opened_channels->prev = NULL;

  • } else {

  • channel->prev->next = channel->next;

  • if (channel->next) channel->next->prev = channel->prev;

  • }
    +}
    +#else
    {
    struct channel ** cp = &caml_all_opened_channels;

    while (*cp != channel && *cp != NULL)
    cp = &(*cp)->next;

  • if (*cp != NULL)
  • if (*cp != NULL) {
    *cp = (*cp)->next;
    }
    +}
    +#endif

CAMLexport void caml_close_channel(struct channel channel)
{
--- io.h.1 2004-01-01 11:42:36.000000000 -0500
+++ io.h 2005-07-15 13:24:35.000000000 -0400
@@ -40,6 +40,7 @@
char * max; /
Logical end of the buffer (for input) /
void * mutex; /
Placeholder for mutex (for systhreads) /
struct channel * next; /
Linear chaining of channels (flush_all) */

  • struct channel * prev; /* Linear chaining of channels (flush_all) /
    int revealed; /
    For Cash only /
    int old_revealed; /
    For Cash only /
    int refcount; /
    For flush_all and for Cash */


@vicuna
Copy link
Author

vicuna commented Sep 24, 2005

Comment author: administrator

see also #3728. Fixed as suggested in main branch, 2005-09-24, XL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant