Improve performance when hosting canvas with many objects

This commit is contained in:
Yousef Khadadeh 2025-07-30 11:36:55 +03:00
parent 207e173c1a
commit b2f2070f95
5 changed files with 28 additions and 30 deletions

View file

@ -74,27 +74,22 @@ void DrawComponent::server_send_erase_set(MainServer& server, const std::unorder
void DrawComponent::server_send_update_temp(MainServer& server, ServerClientID id) {
server.netServer->send_items_to_all_clients(UNRELIABLE_COMMAND_CHANNEL, CLIENT_UPDATE_COMPONENT, true, id, *this);
tempServerUpdateTimer = std::chrono::steady_clock::now();
serverIsTempUpdate = true;
}
void DrawComponent::server_send_update_final(MainServer& server, ServerClientID id) {
server.netServer->send_items_to_all_clients(RELIABLE_COMMAND_CHANNEL, CLIENT_UPDATE_COMPONENT, false, id, *this);
serverIsTempUpdate = false;
}
void DrawComponent::server_send_transform_many(MainServer& server, const std::vector<std::pair<ServerClientID, CoordSpaceHelper>>& transforms) {
server.netServer->send_items_to_all_clients(RELIABLE_COMMAND_CHANNEL, CLIENT_TRANSFORM_MANY_COMPONENTS, transforms);
}
void DrawComponent::server_update(MainServer& server, ServerClientID id) {
if(serverIsTempUpdate) {
float timeSince = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - tempServerUpdateTimer).count();
if(timeSince >= 1.0f) {
server_send_update_final(server, id);
serverIsTempUpdate = false;
}
bool DrawComponent::server_update(MainServer& server, ServerClientID id, const std::chrono::time_point<std::chrono::steady_clock>& tempServerUpdateTimer) {
if((std::chrono::steady_clock::now() - tempServerUpdateTimer) >= CLIENT_DRAWCOMP_DELAY_TIMER_DURATION) {
server_send_update_final(server, id);
return true;
}
return false;
}
void DrawComponent::get_used_resources(std::unordered_set<ServerClientID>& v) const {
@ -112,8 +107,7 @@ bool DrawComponent::bounds_draw_check(const DrawData& drawData) const {
void DrawComponent::check_timers(DrawingProgram& drawP) {
if(delayedUpdatePtr) {
float updateDur = std::chrono::duration_cast<std::chrono::duration<float>>(std::chrono::steady_clock::now() - lastUpdateTime).count();
if(updateDur > CLIENT_DRAWCOMP_DELAY_TIMER_DURATION) {
if(std::chrono::steady_clock::now() - lastUpdateTime > CLIENT_DRAWCOMP_DELAY_TIMER_DURATION) {
update_from_delayed_ptr();
delayedUpdatePtr = nullptr;
final_update(drawP);

View file

@ -14,7 +14,7 @@
#include <include/core/SkVertices.h>
#endif
#define CLIENT_DRAWCOMP_DELAY_TIMER_DURATION 5.0f
#define CLIENT_DRAWCOMP_DELAY_TIMER_DURATION std::chrono::seconds(6)
#define DRAWCOMP_MAX_SHIFT_BEFORE_DISAPPEAR 20
#define DRAWCOMP_MIN_SHIFT_BEFORE_DISAPPEAR 11
@ -71,18 +71,13 @@ class DrawComponent {
void server_send_update_final(MainServer& server, ServerClientID id);
static void server_send_transform_many(MainServer& server, const std::vector<std::pair<ServerClientID, CoordSpaceHelper>>& transforms);
std::chrono::time_point<std::chrono::steady_clock> tempServerUpdateTimer;
bool serverIsTempUpdate = false;
std::weak_ptr<CollabListType::ObjectInfo> collabListInfo;
std::weak_ptr<DrawingProgramCacheBVHNode> parentBvhNode;
void server_update(MainServer& server, ServerClientID id);
bool server_update(MainServer& server, ServerClientID id, const std::chrono::time_point<std::chrono::steady_clock>& tempServerUpdateTimer);
#ifndef IS_SERVER
std::chrono::time_point<std::chrono::steady_clock> lastTransformTime;
std::chrono::time_point<std::chrono::steady_clock> lastUpdateTime;
std::shared_ptr<DrawComponent> delayedUpdatePtr = nullptr;
bool bounds_draw_check(const DrawData& drawData) const;