[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon May 30 11:28:42 UTC 2016


 loolwsd/DocumentBroker.cpp |   43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

New commits:
commit 763eee7040f7a04a0a08e9597307f75b6ebce2a5
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun May 29 17:40:27 2016 -0400

    loolwsd: batch tiles by row
    
    Change-Id: Ib5ca8e1457d4e23aa09968f90ccd3bf10d189815
    Reviewed-on: https://gerrit.libreoffice.org/25661
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index fe4d715..ed6cc55 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -469,11 +469,10 @@ void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
     Log::trace() << "TileCombined request for " << tileCombined.serialize() << Log::end;
 
     // Satisfy as many tiles from the cache.
-    auto& tiles = tileCombined.getTiles();
-    int i = tiles.size();
-    while (--i >= 0)
+    // The rest, group by rows.
+    std::map<int, std::vector<TileDesc>> rows;
+    for (auto& tile : tileCombined.getTiles())
     {
-        auto& tile = tiles[i];
         std::unique_ptr<std::fstream> cachedTile = _tileCache->lookupTile(tile);
         if (cachedTile)
         {
@@ -499,9 +498,7 @@ void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
             cachedTile->close();
 
             session->sendBinaryFrame(output.data(), output.size());
-
-            // Remove.
-            tiles.erase(tiles.begin() + i);
+            continue;
         }
         else
         {
@@ -510,7 +507,7 @@ void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
             if (ver <= 0)
             {
                 // Already rendering. Skip.
-                tiles.erase(tiles.begin() + i);
+                continue;
             }
             else
             if (_cursorPosX >= tile.getTilePosX() && _cursorPosX <= tile.getTilePosX() + tile.getTileWidth() &&
@@ -522,23 +519,39 @@ void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
                 _childProcess->getWebSocket()->sendFrame(req.data(), req.size());
 
                 // No need to process with the group anymore.
-                tiles.erase(tiles.begin() + i);
+                continue;
             }
         }
+
+        const auto tilePosY = tile.getTilePosY();
+        auto it = rows.lower_bound(tilePosY);
+        if (it != rows.end())
+        {
+            it->second.emplace_back(tile);
+        }
+        else
+        {
+            rows.emplace_hint(it, tilePosY, std::vector<TileDesc>({ tile }));
+        }
     }
 
-    if (tiles.empty())
+    if (rows.empty())
     {
         // Done.
         return;
     }
 
-    const auto tileMsg = tileCombined.serialize();
-    Log::debug() << "TileCombined residual request for " << tileMsg << Log::end;
+    auto& tiles = tileCombined.getTiles();
+    for (auto& row : rows)
+    {
+        tiles = row.second;
+        const auto tileMsg = tileCombined.serialize();
+        Log::debug() << "TileCombined residual request for " << tileMsg << Log::end;
 
-    // Forward to child to render.
-    const std::string request = "tilecombine " + tileMsg;
-    _childProcess->getWebSocket()->sendFrame(request.data(), request.size());
+        // Forward to child to render.
+        const std::string request = "tilecombine " + tileMsg;
+        _childProcess->getWebSocket()->sendFrame(request.data(), request.size());
+    }
 }
 
 void DocumentBroker::handleTileResponse(const std::vector<char>& payload)


More information about the Libreoffice-commits mailing list