diff --git a/CHANGELOG b/CHANGELOG
index 06008e78d6b28be976368fc91a5ae20ec35e99ae..57a89a4c173e3acef3dea00d48a5fd7f8eec7900 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
 v 6.6.0
   - Permissions: Developer now can manage issue tracker (modify any issue)
+  - Improve Code Compare page performance
 
 v 6.5.1
   - Fix branch selectbox when create merge request from fork
diff --git a/app/assets/stylesheets/generic/lists.scss b/app/assets/stylesheets/generic/lists.scss
index 245cccf855d627ddfba7592b5fbdbe8e53d0d4c8..de70e47333faa36a67da0a7c50814b15ee35e307 100644
--- a/app/assets/stylesheets/generic/lists.scss
+++ b/app/assets/stylesheets/generic/lists.scss
@@ -23,6 +23,12 @@
       }
     }
 
+    &.warning-row {
+      background-color: #fcf8e3;
+      border-color: #faebcc;
+      color: #8a6d3b;
+    }
+
     &.smoke { background-color: #f5f5f5; }
 
     &:hover {
diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb
index b7531e2cefbf082121ef751b84a021cf4252b56f..696cb7a4ba2d011e369cff0985cfc111829932c1 100644
--- a/app/controllers/projects/compare_controller.rb
+++ b/app/controllers/projects/compare_controller.rb
@@ -8,7 +8,7 @@ class Projects::CompareController < Projects::ApplicationController
   end
 
   def show
-    compare = Gitlab::Git::Compare.new(@repository.raw_repository, params[:from], params[:to])
+    compare = Gitlab::Git::Compare.new(@repository.raw_repository, params[:from], params[:to], MergeRequestDiff::COMMITS_SAFE_SIZE)
 
     @commits       = compare.commits
     @commit        = compare.commit
@@ -16,6 +16,11 @@ class Projects::CompareController < Projects::ApplicationController
     @refs_are_same = compare.same
     @line_notes    = []
 
+    if @diffs == [Gitlab::Git::Diff::BROKEN_DIFF]
+      @diffs = []
+      @timeout = true
+    end
+
     diff_line_count = Commit::diff_line_count(@diffs)
     @suppress_diff = Commit::diff_suppress?(@diffs, diff_line_count) && !params[:force_show_diff]
     @force_suppress_diff = Commit::diff_force_suppress?(@diffs, diff_line_count)
diff --git a/app/views/projects/compare/_form.html.haml b/app/views/projects/compare/_form.html.haml
index 0762655fb930dfedd49f685c8bc09753921d54fc..da6157cf1b615789e28868b91856a774c0b8c0ef 100644
--- a/app/views/projects/compare/_form.html.haml
+++ b/app/views/projects/compare/_form.html.haml
@@ -14,7 +14,7 @@
     &nbsp;
     = submit_tag "Compare", class: "btn btn-create commits-compare-btn"
     - if compare_to_mr_button?
-      = link_to compare_mr_path, class: 'prepend-left-10' do
+      = link_to compare_mr_path, class: 'prepend-left-10 btn' do
         %strong Make a merge request
 
 
diff --git a/app/views/projects/compare/show.html.haml b/app/views/projects/compare/show.html.haml
index e9456c24960c4e056106ffe0f0ab9eb0c2a29261..9bd498553697169a56881c5a7dc3b224f022ad48 100644
--- a/app/views/projects/compare/show.html.haml
+++ b/app/views/projects/compare/show.html.haml
@@ -5,21 +5,32 @@
 
 = render "form"
 
-- if @commits.size > 100
-  .alert.alert-warning
-    %p
-      %strong Warning! This comparison includes more than 100 commits.
-    %p To preserve performance the line diff is not shown.
-
 - if @commits.present?
   %div.ui-box
     .title
       Commits (#{@commits.count})
-    %ul.well-list= render Commit.decorate(@commits), project: @project
+    - if @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE
+      %ul.well-list
+        - Commit.decorate(@commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE)).each do |commit|
+          = render "projects/commits/inline_commit", commit: commit, project: @project
+        %li.warning-row.unstyled
+          other #{@commits.size - MergeRequestDiff::COMMITS_SAFE_SIZE} commits hidden to prevent performance issues.
+    - else
+      %ul.well-list= render Commit.decorate(@commits), project: @project
 
-  - unless @diffs.empty?
-    %h4 Diff
+  %h4 Diff
+  - if @diffs.present?
     = render "projects/commits/diffs", diffs: @diffs, project: @project
+  - elsif @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE
+    .bs-callout.bs-callout-danger
+      %h4 This comparison includes more than #{MergeRequestDiff::COMMITS_SAFE_SIZE} commits.
+      %p To preserve performance the line diff is not shown.
+  - elsif @timeout
+    .bs-callout.bs-callout-danger
+      %h4 Diff for this comparison is extremely large.
+      %p Use command line to browse diff for this comparison.
+
+
 - else
   .light-well
     %center