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 61263 - Experiment to speed up IMAP folder scannning
Experiment to speed up IMAP folder scannning
Status: VERIFIED FIXED
Product: balsa
Classification: Other
Component: general
1.2.x
Other Linux
: Normal enhancement
: ---
Assigned To: Balsa Maintainers
Balsa Maintainers
Depends on:
Blocks:
 
 
Reported: 2001-09-27 00:50 UTC by PeterBloomfield
Modified: 2009-08-15 18:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
the patch (6.63 KB, patch)
2001-09-27 00:51 UTC, PeterBloomfield
none Details | Review
Another experiment (19.75 KB, patch)
2001-10-16 13:56 UTC, PeterBloomfield
none Details | Review
patch against cvs of Oct 25 '01 (19.91 KB, patch)
2001-10-25 15:10 UTC, PeterBloomfield
none Details | Review
patch against current cvs (20.16 KB, patch)
2001-12-03 21:05 UTC, PeterBloomfield
none Details | Review
Patch against current cvs (19.46 KB, patch)
2001-12-05 20:56 UTC, PeterBloomfield
none Details | Review

Description PeterBloomfield 2001-09-27 00:50:43 UTC
This is related to bug #60785. Recently I have been getting *very* slow
ping times to my IMAP server (up to 2 seconds--and it's about 2 miles
away!). Balsa takes minutes to start up, and then dies an instant after
displaying the main window (firing it up immediately, it never dies the
same way--weird!).

So...how to speed up the folder scanning when a round-trip message takes a
second or two?  Balsa asks the server to list all subfolders of all
mailboxes, and current code *waits for the response* for one folder before
asking about the next.  This isn't necessary!  We need the list of folders
at one depth in the tree, to know where to look for the next level, but we
can start several requests at once.

This patch, which is strictly experimental (that is, it works for me, but
ymmv), sends multiple requests, picking up responses as they come, and
waits for everything to come back only when absolutely necessary--in this
case, after scanning all folders at a given level. It builds a list of
outstanding requests and checks them off as they are completed.

Affected files:
- libbalsa/folder-scanners.c: let the libmutt code that the 
  current series of requests is finished
- libmutt/imap/browse.c: much rewriting
- libmutt/browser.h: add seq_list field to struct browser_state
Comment 1 PeterBloomfield 2001-09-27 00:51:34 UTC
Created attachment 5703 [details] [review]
the patch
Comment 2 Carlos Morgado 2001-09-27 22:59:51 UTC
Broke somewhat for me on uw-imap. It created 7 nameless folders with
no leafs under the root. This happened on 2 diferent machines with
diferent versions of uw-imapd. Parsed the existing folders correctly
as far as i can tell.
Worked with myrealbox.com (novell server)
Comment 3 PeterBloomfield 2001-10-16 13:56:02 UTC
Created attachment 5836 [details] [review]
Another experiment
Comment 4 PeterBloomfield 2001-10-16 14:17:11 UTC
Hazardous content--highly experimental--yhbw.

The attachment labeled `Another experiment' reflects much debate about
the imap protocol, especially about `subscribed' mailboxes and the
various servers' idiosyncracies. It's very fast when asked to list
`subscribed folders only'.

The strategy in this case is to use LSUB prefix/* to see *all* of the
subscribed folders with a single command.  As each response is
received, a LIST path/% command is issued, where `path' is the path to
the latest folder with the last level removed; this ensures that we
get a LIST response for the current folder, and the flags are ORed
with those, if any, on the original LSUB response.  The folder tree is
then built, with synthetic nodes to fill in any missing layers in the
hierarchy.

There's also some record-keeping and other tweaking to avoid redundant
commands.  The net result is that network traffic and latency is
minimized: commands are reduced by up to 90%, and many overlap; there
are two responses for each subscribed folder, plus one for any
unsubscribed folder in the same parent folder as a subscribed folder. 
It's hard to see how to reduce this count.

The strategy for `all folders' is more cautious: use LIST path/% to
descend the tree recursively, one level at a time, rather than LIST
prefix/*.  This is to avoid: (i) endless responses when the mailstore
has circular references; and (ii) voluminous responses when the user
has, for instance, the whole of usenet news in the namespace.  Again,
the commands are overlapped as far as possible, to reduce latency. 
However, LIST path/% is issued for every leaf node, with no responses
naturally, and this generates many command/response sequences.

Affected files are much as for the previous attempt, with some minor
changes to src/mailbox-node.c to cope more sensibly with the case of a
nonnull prefix that's a real mailbox.
Comment 5 PeterBloomfield 2001-10-25 15:10:42 UTC
Created attachment 5908 [details] [review]
patch against cvs of Oct 25 '01
Comment 6 PeterBloomfield 2001-10-25 15:12:13 UTC
The above patch implements the same changes, wrt current (Oct 25 '01)
cvs.
Comment 7 Pawel Salek 2001-11-17 20:59:15 UTC
Is this ready for CVS?
Comment 8 PeterBloomfield 2001-11-18 03:57:05 UTC
I used this code for a while with a Cyrus server with no problems, and
the strategy was designed to work with uw-imap also, but I don't know
if anyone tested that. I think it has some real benefits, but...

Carlos mentioned something about getting asynch imap i/o in libmutt a
week or two ago. If something more general is in the works, I'd
suggest waiting for it. These changes make browsing work quite
differently for Balsa than for mutt, so there may be some difficulties
down the road keeping things in sync.

I guess there are some issues here that I don't feel competent to
comment on. 
Comment 9 PeterBloomfield 2001-12-03 21:04:00 UTC
The following patch is a cleaned-up version of an earlier experiment,
which browses the folder tree only far enough to find out whether the
viewable nodes have children. It works by restricting the folder
browsing to depth 1 (below the current node), with further browsing
triggered by exposing more of the tree.

The depth can be specified through the prefs page, so setting it to 7
would reproduce the current behavior, while setting it to 1 (the
lowest value) gives the fastest start with the least browsing. The
option is on the `Startup' page, and applies to any IMAP account. It
should perhaps be server-specific, and located in the folder-conf
dialog; I chose not to put it there, as that dialog is getting pretty
crowded, but that could be fixed. A corresponding update to
help/C/balsa.sgml is included (with some other minor IMAP changes).

Files:
help/C/balsa.sgml:		documentation.
libbalsa/folder-scanners.c:	add state.scanned--set it, pass 
				it to the handlers;
libbalsa/folder-scanners.h:	change handler prototype.
libmutt/browser.h:		new member `scanned' in struct 
				browser_state.
src/balsa-app.[hc]:		add balsa_app.imap_scan_depth
src/balsa-mblist.[hc]:		change "tree-expand" callback to
				connect-after;
				unrelated cleanup of 
				balsa_mblist_repopulate;
				add balsa_mblist_scan_children, for
				appending subtrees when needed;
				add mblist_scan_mailbox_node as the
				corresponding public interface. 
src/mailbox-node.[hc]:		add mbnode->scanned, and set it;
				pass balsa_app.imap_scan_depth
				to libbalsa_scanner_imap_dir;
				call mblist_scan_mailbox_node.
src/pref-manager.c:		manage balsa_app.imap_scan_depth.
src/save-restore.c:		ditto.
Comment 10 PeterBloomfield 2001-12-03 21:05:14 UTC
Created attachment 6131 [details] [review]
patch against current cvs
Comment 11 PeterBloomfield 2001-12-05 20:53:26 UTC
Attachment 6131 [details] is a bit untidy, with some code transplanted from
mailbox-node.c to balsa-mblist.c. The following is cleaner, and
handles rescanning properly. It does delete a `g_return_' test that
doesn't seem necessary--if I'm missing something, please let me know!
Comment 12 PeterBloomfield 2001-12-05 20:56:07 UTC
Created attachment 6161 [details] [review]
Patch against current cvs
Comment 13 Pawel Salek 2001-12-05 22:51:05 UTC
Attachment 6161 [details] commited, thanks.
This hopefully resolves the issue(?).
Comment 14 Pawel Salek 2002-01-16 22:54:22 UTC
I close this report.
Comment 15 Pawel Salek 2002-04-25 08:45:25 UTC
balsa-1.3.5 and 2.0.0 released, closing this report for good.