🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #4328

Re: Tin v1.2 PL0 newsreader Bug List

#4328
From: Pope Clifton
Date: Wed, 02 Jun 1993 02:12
375 lines
11828 bytes
This is not _exactly_ a bug fix, but I figured many users would want to know,
since it's the second most serious annoyance with Tin. (#1 being the XRef
that Iain is working on.)

I figured out what was making the "Checking for new newsgroups" take so long
for local (non-NNTP) newspools, and rewrote that section with a new
algorithm.  I estimate that on a system with ~4000 newsgroups (like Netcom)
it will now take about 1/80 the time.  In practise, I can just see the
"checking..." message flash on the screen before it is replaced by the first
new group query.

I'm posting the patch here, and it's also on its way to Iain.  This time I
got the order of the diffs right.  However, it's first draft code, and
though some simple test cases worked right, it still may not be perfect. 
Apply with caution.  

*** orig/active.c	Tue Jun  1 18:22:17 1993
--- my/active.c	Tue Jun  1 18:51:27 1993
***************
*** 21,26 ****
--- 21,66 ----
  int active_index = -1;
  
  /*
+  * notify_t structure definiton was formerly internal to the
+  * check_for_any_new_groups function.
+  */
+ 
+ struct notify_t {
+ 		char name[PATH_LEN];
+ 		int visited;
+ 	};
+ 
+ /*
+  * It's easy to be confused by arrays of pointers to pointers, so
+  * typedefs are used for the first level pointers to keep it clearer.
+  */
+ 
+ typedef struct group_t * group_p;
+ typedef struct notify_t * notify_p;
+ 
+ /*
+  *  Compare two pointers to "group_t" structures - used in qsort.
+  */
+ 
+ int cmp_group_p (first, second)
+ 	group_p *first, *second;
+ {
+ 	return( strcmp( (*first)->name, (*second)->name ) );
+ }
+ 
+ 
+ /*
+  *  Compare two pointers to "notify_t" structures - used in qsort.
+  */
+ 
+ int cmp_notify_p (first, second)
+ 	notify_p *first, *second;
+ {
+ 	return( strcmp( (*first)->name, (*second)->name ) );
+ }
+ 
+ 
+ /*
   *  Get default array size for active[] from environment (AmigaDOS)
   *  or just return the standard default.
   */
***************
*** 89,95 ****
  	i = group_hash[h];
  	
  	/* 
! 	 * hash linked list chaining 
  	 */
  	while (i >= 0) {
  		if (strncmp (group, active[i].name, strlen (active[i].name)) == 0) {
--- 129,135 ----
  	i = group_hash[h];
  	
  	/* 
! 	 * hash linked list chaining
  	 */
  	while (i >= 0) {
  		if (strncmp (group, active[i].name, strlen (active[i].name)) == 0) {
***************
*** 159,165 ****
  }
  
  /*
!  *  Load the news active file into active[] and create copy 
   *  of active ~/.tin/active
   */
  
--- 199,205 ----
  }
  
  /*
!  *  Load the news active file into active[] and create copy
   *  of active ~/.tin/active
   */
  
***************
*** 309,315 ****
  	char buf[LEN], *ptr;
  	FILE *fp = (FILE *) 0;
  	int group_not_found;
! 	int ch, num = 0;
  	int ch_default = 'n';
  	int update_old_active = FALSE;
  	int max_old_active;
--- 349,355 ----
  	char buf[LEN], *ptr;
  	FILE *fp = (FILE *) 0;
  	int group_not_found;
! 	int ch, num = 0;	/* num == num_old_active groups */
  	int ch_default = 'n';
  	int update_old_active = FALSE;
  	int max_old_active;
***************
*** 316,329 ****
  	int new_active_size;
  	int old_active_size;
  	long epoch;
  	register int i, j;
  	struct stat sb;
  	struct tm *tm;
- 	struct notify_t {
- 		char name[PATH_LEN];
- 		int visited;
- 	} *old_active = (struct notify_t *) 0;
  
  	if ((! check_for_new_newsgroups || (update && ! update_fork))) {
  		return;
  	}
--- 356,372 ----
  	int new_active_size;
  	int old_active_size;
  	long epoch;
+ 	int compared;
  	register int i, j;
  	struct stat sb;
  	struct tm *tm;
  
+ 	notify_p old_active = (notify_p) 0;
+ 
+ 	notify_p *sorted_old_active = (notify_p *) 0;
+ 
+ 	group_p *sorted_active = (group_p *) 0;
+ 
  	if ((! check_for_new_newsgroups || (update && ! update_fork))) {
  		return;
  	}
***************
*** 352,364 ****
  	 * find out if we have read news from here before otherwise -1
  	 */
  	active_index = find_active_size_index (new_active_file_server);
! 		
  	if (debug == 2) {
  		if (active_index >= 0) {	
! 			strcpy (old_active_file_server, active_size[active_index].server); 
  			strcpy (old_active_file_attribute, active_size[active_index].attribute);
  		} else {
! 			strcpy (old_active_file_server, "UNKNOWN"); 
  			strcpy (old_active_file_attribute, "UNKNOWN");
  		}	
  		sprintf (msg, "Active size index=[%d]  old=[%s %s]  new=[%s %s]", 
--- 395,407 ----
  	 * find out if we have read news from here before otherwise -1
  	 */
  	active_index = find_active_size_index (new_active_file_server);
! 
  	if (debug == 2) {
  		if (active_index >= 0) {	
! 			strcpy (old_active_file_server, active_size[active_index].server);
  			strcpy (old_active_file_attribute, active_size[active_index].attribute);
  		} else {
! 			strcpy (old_active_file_server, "UNKNOWN");
  			strcpy (old_active_file_attribute, "UNKNOWN");
  		}	
  		sprintf (msg, "Active size index=[%d]  old=[%s %s]  new=[%s %s]", 
***************
*** 390,406 ****
  
  	Raw (TRUE);
  
! 	old_active = (struct notify_t *) my_malloc ((unsigned) sizeof (struct notify_t) * max_old_active);
! 	if (old_active == (struct notify_t *) 0) {
  		error_message (txt_out_of_memory, progname);
  		goto notify_groups_done;
  	}
! 	
  	while (fgets (buf, sizeof (buf), fp) != NULL) {
  		if (buf[0] == '.') {
  			break;
  		}
! 		strncpy (old_active[num].name, buf, sizeof (old_active[num].name));		
  		ptr = old_active[num].name;
  		while (*ptr && *ptr != ' ' && *ptr != '\n') {
  			ptr++;
--- 433,449 ----
  
  	Raw (TRUE);
  
! 	old_active = (notify_p) my_malloc ((unsigned) sizeof (struct notify_t) * max_old_active);
! 	if (old_active == (notify_p) 0) {
  		error_message (txt_out_of_memory, progname);
  		goto notify_groups_done;
  	}
! 
  	while (fgets (buf, sizeof (buf), fp) != NULL) {
  		if (buf[0] == '.') {
  			break;
  		}
! 		strncpy (old_active[num].name, buf, sizeof (old_active[num].name));
  		ptr = old_active[num].name;
  		while (*ptr && *ptr != ' ' && *ptr != '\n') {
  			ptr++;
***************
*** 410,419 ****
  		num++;
  		if (num >= max_old_active) {
  			max_old_active= max_old_active + (max_old_active / 2);
! 			old_active= (struct notify_t*) my_realloc(
! 				(char *) old_active, 
  				(unsigned) sizeof(struct notify_t) * max_old_active);
! 			if (old_active == (struct notify_t *) 0) {
  				error_message (txt_out_of_memory, progname);
  				goto notify_groups_done;
  			}
--- 453,462 ----
  		num++;
  		if (num >= max_old_active) {
  			max_old_active= max_old_active + (max_old_active / 2);
! 			old_active= (notify_p) my_realloc(
! 				(char *) old_active,
  				(unsigned) sizeof(struct notify_t) * max_old_active);
! 			if (old_active == (notify_p) 0) {
  				error_message (txt_out_of_memory, progname);
  				goto notify_groups_done;
  			}
***************
*** 436,458 ****
  		}
  	} else {	
  		wait_message (txt_checking_active_file);
! 		for (i = 0 ; i < num_active ; i++) {	
  			group_not_found = TRUE;
! 			for (j=0; j < num ; j++) {
! 				if (strcmp (old_active[j].name, active[i].name) == 0) {
! 					group_not_found = FALSE;	/* found it so read in next group */
! 					old_active[j].visited = TRUE;
! 					break;
! 				}
  			}
  
  			if (group_not_found == FALSE) {
  				continue;
! 			}	
! 	
  			update_old_active = TRUE;
! 	
! 			if (! prompt_subscribe_group (active[i].name)) {
  				if (cmd_line) {
  					printf ("\r\n");
  					fflush (stdout);
--- 479,546 ----
  		}
  	} else {	
  		wait_message (txt_checking_active_file);
! 		/*
! 		 * Clifton Royston 6/1/93
! 		 * The following code replaces the original check for new newsgroups,
! 		 * a source of much aggravation.
! 		 *
! 		 * The original algorithm compared each group name in active to (on
! 		 * average) 1/2 the groups in old_active, for ~N*N/2 string compares.
! 		 * This works out to ~~ 8,000,000 comparisons for 4000 newsgroups.
! 		 *
! 		 * The new algorithm allocates an array of pointers to the active
! 		 * and old_active array elements, sorts each pointer array with
! 		 * quicksort, then scans through the two arrays in 1 pass; this takes
! 		 * 2*N*Log2(N) string compares for the sorts, N for the final pass.
! 		 * This should work out to ~~ 100,000 comparisons for the same 4000
! 		 * newsgroups, a BIG, BIG win.
! 		 */
! 
! 		/* Allocate arrays to be sorted */
! 		sorted_active = (group_p *) my_malloc(
! 			(unsigned) sizeof (group_p) * num_active );
! 		if (sorted_active == (group_p *) 0) {
! 			error_message (txt_out_of_memory, progname);
! 			goto notify_groups_done;
! 		}
! 		sorted_old_active = (notify_p *) my_malloc(
! 			(unsigned) sizeof (notify_p) * num );
! 		if (sorted_old_active == (notify_p *) 0) {
! 			error_message (txt_out_of_memory, progname);
! 			goto notify_groups_done;
! 		}
! 
! 		/* Fill arrays to be sorted */
! 		for (i = 0 ; i < num_active ; i++)
! 			sorted_active[i] = &active[i];
! 		for (j = 0 ; j < num ; j++)
! 			sorted_old_active[j] = &old_active[j];
! 
! 		/* Sort the arrays */
! 		qsort( sorted_active, num_active, sizeof(group_p), cmp_group_p );
! 		qsort( sorted_old_active, num, sizeof(notify_p), cmp_notify_p );
! 
! 		/* Now do the pass through both arrays at once */
! 		j = 0;
! 		for (i = 0 ; i < num_active ; i++) {
  			group_not_found = TRUE;
! 			compared = 1;
! 			while ( (j < num) && ( 0 > 
! 				(compared = strcmp (sorted_old_active[j]->name, sorted_active[i]->name) ) ) )
! 				j++;
! 			if (compared == 0) {
! 				group_not_found = FALSE;	/* found it so read in next group */
! 				sorted_old_active[j]->visited = TRUE;
! 				j++;
  			}
  
  			if (group_not_found == FALSE) {
  				continue;
! 			}
! 
  			update_old_active = TRUE;
! 
! 			if (! prompt_subscribe_group (sorted_active[i]->name)) {
  				if (cmd_line) {
  					printf ("\r\n");
  					fflush (stdout);
***************
*** 532,540 ****
  		load_active_size_info (buf);
  	}
  
! 	if (old_active != (struct notify_t *) 0) {
  		free ((char *) old_active);
! 		old_active = (struct notify_t *) 0;
  	}
  
  	if (cmd_line) {
--- 620,641 ----
  		load_active_size_info (buf);
  	}
  
! 	/*
! 	 * Free malloc'd arrays
! 	 */
! 	if (old_active != (notify_p) 0) {
  		free ((char *) old_active);
! 		old_active = (notify_p) 0;
! 	}
! 
! 	if (sorted_old_active != (notify_p *) 0) {
! 		free ((char *) sorted_old_active);
! 		sorted_old_active = (notify_p *) 0;
! 	}
! 
! 	if (sorted_active != (group_p *) 0) {
! 		free ((char *) sorted_active);
! 		sorted_active = (group_p *) 0;
  	}
  
  	if (cmd_line) {


--
cliftonr@netcom.com     Home: +1 808 521 9073  Work: +1 808 625 3234
Clifton Royston, Pope of the Church of the Subgenius in Paradise
"Well now I don't know about that.  I'm a skeptic." -- John_-_Winston
Technical Details
Message-ID: <cliftonrC7z250.2KD@netcom.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!decwrl!netcomsv!netcom.com!cliftonr
References: <1993May25.071802.10899@anl433.uucp> <cliftonrC7pLz3.B1r@netcom.com>

Show Full Headers
Complete Article Headers
Message-ID: <cliftonrC7z250.2KD@netcom.com>
Subject: Re: Tin v1.2 PL0 newsreader Bug List
Date: Wed, 2 Jun 1993 02:12:35 GMT
From: cliftonr@netcom.com (Pope Clifton)
References: <1993May25.071802.10899@anl433.uucp> <cliftonrC7pLz3.B1r@netcom.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!decwrl!netcomsv!netcom.com!cliftonr
Newsgroups: news.software.readers,alt.sources.patches
Followup-To: news.software.readers
Organization: Inst. for Epistemological Pathology
X-Newsreader: TIN [version 1.2 PL0]
Lines: 375