ice icon indicating copy to clipboard operation
ice copied to clipboard

Cache Swift Connection objects

Open externl opened this issue 4 years ago • 1 comments

Right now, we create a new Swift Connection object each time we create a new Current during dispatch.

We should consider caching this connection object so we don't have to recreate it every time.

One possibility would be to install a close callback on the C++ object which holds the Swift object in the closure.

We should also maybe measure the performance to see if it really makes a big difference.

externl avatar Oct 10 '19 15:10 externl

I tried with a modified latency demo and did not find a noticeable difference with/without Swift connection caching. With this demo, there is a single client that establishes one connection and makes many ice_ping calls to the server.

class PingI: Ice.ObjectI<PingTraits>, Ping {
    override func ice_ping(current: Ice.Current) {
        if _con == nil {
            _con = current.con
        }
    }
    private var _con: Ice.Connection?
}

bernardnormier avatar Oct 10 '19 19:10 bernardnormier