title: Performance optimizations of LineBreakMeasurer
body: <p>I am currently writing a text block with syntax highlighting in OpenGL and to layout my lines correctly with line wrapping I am using AWTs <code>LineBreakMeasurer</code>. The visual results are perfect, the performance is OK, however I was wondering if there are possibilities to make it a bit faster. Currently it takes on average 2-3 milliseconds for one line of text to be laid out.</p>
  
  <p>So this is the code that is currently used to do the layout</p>
  
  <pre><code>private fun calculateLineLayout(line: AttributedString, graphics: Graphics2D, width: Int, layouts: ArrayList&lt;TextLayout&gt;): Float {
      val iterator = line.iterator
      if(iterator.beginIndex &gt;= iterator.endIndex) {
          return 0.0f
      }
  
      val end = iterator.endIndex
      val measurer = LineBreakMeasurer(iterator, graphics.fontRenderContext)
      measurer.position = iterator.beginIndex
  
      var sizeY = 0.0f
      while(measurer.position &lt; end) {
          val layout = measurer.nextLayout(width.toFloat())
          layouts.add(layout)
          sizeY += layout.ascent + layout.descent + layout.leading
      }
  
      return sizeY
  }
  </code></pre>
  
  <p>My questions would be </p>
  
  <ul>
  <li>Are there alternatives to <code>LineBreakMeasurer</code> from AWT that are more efficient?</li>
  <li>Could there be optimization potential from the fact, that the font will always be monospaced and therefore the number of characters in a line is already deductible from the width?</li>
  </ul>