title: TableView cells with collectionView performance issue
body: <p>I have the following layout:<a href="https://i.stack.imgur.com/cHlwz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cHlwz.png" alt="enter image description here"></a>
  When scrolling the tableView fps drops to around 25 and it becomes very jittering.  </p>
  
  <p>I think it's my implementation of the collectionView since a lot of operations are performed in cellForIndexAtPath. But I can't see what can be optimized?</p>
  
  <pre><code>extension MyTableViewController: UICollectionViewDelegate, UICollectionViewDataSource {
  
  func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int
  {
      // No sections are longer than 99
      if(collectionView.tag &lt; 100)
      {
          let code = codes0[collectionView.tag].objectForKey("code") as! String
  
          return code.componentsSeparatedByString(",").count
      }
      else if(collectionView.tag &lt; 200)
      {
          let code = codes1[collectionView.tag-100].objectForKey("code") as! String
  
          return code.componentsSeparatedByString(",").count
      }
      else
      {
          let code = codes2[collectionView.tag-200].objectForKey("code") as! String
  
          return code.componentsSeparatedByString(",").count
      }
  }
  
  func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell
  {
      let cell = collectionView.dequeueReusableCellWithReuseIdentifier("code", forIndexPath: indexPath) as! ImageCodeCollectionViewCell
  
      // Read that this should help for GPU
      cell.layer.shouldRasterize = true
      cell.layer.rasterizationScale = UIScreen.mainScreen().scale
  
      var codeLength:String! = ""
  
      if(collectionView.tag &lt; 100)
      {
          codeLength = self.codes0[collectionView.tag].objectForKey("code") as! String
      }
      else if(collectionView.tag &lt; 200)
      {
          codeLength = self.codes1[collectionView.tag-100].objectForKey("code") as! String
      }
      else
      {
          codeLength = self.codes2[collectionView.tag-200].objectForKey("code") as! String
      }
  
      let cLength = codeLength.componentsSeparatedByString(",")
  
      if(indexPath.row &lt;= cLength.count)
      {
          cell.imageCode.image = UIImage(named: cLength[indexPath.row])
      }
  
      return cell
  }
  </code></pre>
  
  <p><strong>My tableView looks like:</strong></p>
  
  <p>Here's the collectionView data source and delegate set</p>
  
  <pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell
  {
      let cell = tableView.dequeueReusableCellWithIdentifier("cheat") as! CodeTableViewCell
  
      cell.layer.shouldRasterize = true
      cell.layer.rasterizationScale = UIScreen.mainScreen().scale
  
      cell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row, forSection: indexPath.section)
  
      return cell
  }
  
  func tableView(tableView: UITableView, willDisplayCell cell: CodeTableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
  {
      switch indexPath.section
      {
      case 2:
          cell.name = codes2[indexPath.row].objectForKey("name") as! String
  
          cell.descript = ((codes2[indexPath.row].objectForKey("description") as! String).isEmpty ? "-" : codes2[indexPath.row].objectForKey("description") as! String)
  
      case 1:
          cell.name = codes1[indexPath.row].objectForKey("name") as! String
  
          cell.descript = ((codes1[indexPath.row].objectForKey("description") as! String).isEmpty ? "-" : codes1[indexPath.row].objectForKey("description") as! String)
  
      default:
          cell.name = codes0[indexPath.row].objectForKey("name") as! String
  
          cell.descript = ((codes0[indexPath.row].objectForKey("description") as! String).isEmpty ? "-" : codes0[indexPath.row].objectForKey("description") as! String)
      }
  }
  </code></pre>