I found the solution by the comment from birgire what tells to use
wp_defer_term_counting()
as follows:
if( ! $errors ) {
// Set wp_defer_comment_counting();
wp_defer_term_counting( true );
foreach( $lines as $line ) {
// Import post
$args = array(
'post_title' => $new_vipost_title,
'post_content' => $new_vipost_content,
'post_status' => 'publish',
'post_type' => $vipost_type,
);
$post_id = wp_insert_post( $args );
update_post_meta( $post_id, 'vimport_key', $import_key );
// Set term if isset
wp_set_object_terms( $post_id, $viterm, $vitax, false );
}
// Set wp_defer_comment_counting( false );
wp_defer_comment_counting( false );
} else {
$_POST['errors'] = true;
}