     @lines.css fontSize: "#{@editorView.getFontSize()}px"
 
     @markIntermediateTime('cleaning')
-    # FIXME: If the file is very large, the tokenizes doesn't generate
-    # completely, so doesn't have the syntax highlight until a new view
-    # is activated in the same pane.
+
     numLines = @editorView.getModel().displayBuffer.getLines().length
-    lines = @editorView.buildLineElementsForScreenRows(0, numLines)
 
-    @markIntermediateTime('lines building')
     wrapper = $('<div/>')
-    wrapper.append lines
     @lines.append wrapper
 
-    @endBench('minimap update')
+    batchSize = 100
+    batch = (start=0) =>
+      end = Math.min(start + batchSize, numLines)
+      @log start, end
+      lines = @editorView.buildLineElementsForScreenRows(start, end)
+
+      @markIntermediateTime('batch finished')
+      wrapper.append lines
+      if end is numLines
+        @rebuilding = false
+        @endBench('minimap update')
+        @emit 'minimap:updated'        
+      else
+        webkitRequestAnimationFrame -> batch(end + 1)
+
+    batch()
 
   getClientRect: ->
     sv = @scrollView[0]


  update: =>
    return unless @editorView?
    return if @frameRequested

    @frameRequested = true
    webkitRequestAnimationFrame =>
      @frameRequested = false
      if @bufferChanges.length > 0
        @updateMinimapWithBufferChanges()
      else
        @rebuildMinimap()

      @emit 'minimap:updated'

  updateMinimapWithBufferChanges: ->
    @startBench()

Debug = require 'prolix'

module.exports =
class MinimapPaneView extends ScrollView
  Emitter.includeInto(this)
  Debug('minimap').includeInto(this)

