Index: wordpress/wp-includes/comment.php
===================================================================
--- wordpress/wp-includes/comment.php	(revision 6528)
+++ wordpress/wp-includes/comment.php	(working copy)
@@ -491,8 +491,41 @@
 	return $rval;
 }
 
+function wp_defer_comment_counting($defer=NULL) {
+	static $_defer = false;
+	
+	if ( is_bool($defer) ) {
+		$_defer = $defer;
+		// flush any deferred counts
+		if ( !$defer )
+			wp_update_comment_count( NULL, true );
+	}
+	
+	return $_defer;
+}
 
-function wp_update_comment_count($post_id) {
+function wp_update_comment_count($post_id, $do_deferred=false) {
+	static $_deferred = array();
+	
+	if ( $do_deferred ) {
+		$_deferred = array_unique($_deferred);
+		foreach ( $_deferred as $i => $_post_id ) {
+			wp_update_comment_count_now($_post_id);
+			unset( $_deferred[$i] );
+		}
+	}
+	
+	if ( wp_defer_comment_counting() ) {
+		$_deferred[] = $post_id;
+		return true;
+	}
+	elseif ( $post_id ) {
+		return wp_update_comment_count_now($post_id);
+	}
+		
+}
+
+function wp_update_comment_count_now($post_id) {
 	global $wpdb;
 	$post_id = (int) $post_id;
 	if ( !$post_id )
Index: wordpress/wp-admin/import/wordpress.php
===================================================================
--- wordpress/wp-admin/import/wordpress.php	(revision 6528)
+++ wordpress/wp-admin/import/wordpress.php	(working copy)
@@ -376,7 +376,9 @@
 			$cat_index++;
 		}
 
-		if ($post_id = post_exists($post_title, '', $post_date)) {
+		$post_exists = post_exists($post_title, '', $post_date);
+		
+		if ( $post_exists ) {
 			echo '<li>';
 			printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
 		} else {
@@ -475,7 +477,8 @@
 			$comment_type         = $this->get_tag( $comment, 'wp:comment_type');
 			$comment_parent       = $this->get_tag( $comment, 'wp:comment_parent');
 
-			if ( !comment_exists($comment_author, $comment_date) ) {
+			// if this is a new post we can skip the comment_exists() check
+			if ( !$post_exists || !comment_exists($comment_author, $comment_date) ) {
 				$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
 				wp_insert_comment($commentdata);
 				$num_comments++;
@@ -648,35 +651,45 @@
 		return apply_filters('import_attachment_size_limit', 0);
 	}
 	
+	function import_start() {
+		wp_defer_term_counting(true);
+		wp_defer_comment_counting(true);
+		do_action('import_start');
+	}
+	
+	function import_end() {
+		do_action('import_end');
+		
+		// clear the caches after backfilling
+		foreach ($this->post_ids_processed as $post_id)
+			clean_post_cache($post_id);
+		
+		wp_defer_term_counting(false);
+		wp_defer_comment_counting(false);
+	}
 
 	function import($id, $fetch_attachments = false) {
 		$this->id = (int) $id;
 		$this->fetch_attachments = ($this->allow_fetch_attachments() && (bool) $fetch_attachments);
 
 		add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
-		do_action('import_start');
 		$file = get_attached_file($this->id);
 		$this->import_file($file);
-		do_action('import_end');
 	}
 		
 	function import_file($file) {
 		$this->file = $file;
 		
+		$this->import_start();
 		$this->get_authors_from_post();
-		wp_defer_term_counting(true);
 		$this->get_entries();
 		$this->process_categories();
 		$this->process_tags();
 		$result = $this->process_posts();
 		$this->backfill_parents();
 		$this->backfill_attachment_urls();
+		$this->import_end();
 		
-		// clear the caches after backfilling
-		foreach ($this->post_ids_processed as $post_id)
-			clean_post_cache($post_id);
-		
-		wp_defer_term_counting(false);
 		if ( is_wp_error( $result ) )
 			return $result;
 	}
