Currently, it looks like you are looping through comments and then querying the posts from there. Could you use the comment_count
order by parameter directly in the posts query itself?
For example:
<?php
$post_args = array(
'post_type' => 'portfolio',
'posts_per_page' => 1,
'orderby' => 'comment_count'
);
$posts = get_posts($post_args);
foreach ($posts as $post) : setup_postdata($post);
$title = get_the_title($comment->comment_post_ID);
?>
<div class="col-md-3 col-sm-6 col-xs-12">
<h4><?php echo $title; ?></h4>
</div>
<?php
endforeach;
Source: https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters