- WebRTC Clients
- Codecs weight
- DNS lookup Time
- Bandwidth Estimation
- Best practices for WebRTC web clients
- Cookies – Security vs persistent state
- Web Client Performance monitoring
- Web Workers
- Native Applications on mobile OS
- Threads and Cores
- CPU profiling
- Energy consumption
This post is about making performance enhancements to a WebRTC app so that they can be used in the area which requires sensitive data to be communicated, cannot afford downtime, fast response and low RTT, need to be secure enough to withstand and hacks and attacks.
- Single-page applications (HTML5 + Js + CSS) on browser engine on OS
- Electron app
- Facebook Messenger, slack , twitch are some of the RTC based applications which have have electron clients as well.
- Web-view on mobile
- (-) doesn’t have advanced Webrtc API support eg, Media Recorder
- Native Applications on mobile OS( Android, iOS)
- Hybrid Applications (React Native)
- Embedded Device ( set-top box, IP camera, robots on raspberry pi)
- raw codecs libraries and gstt=reamer/FFmpeg script to create RTSP stream
opus (111, minptime=10;useinbandfec=1)
Services such as Pingdom (https://tools.pingdom.com/) or WebPageTest can quickly calculate your website’s DNS lookup times.
Load / sgtress testing for Caching and lookup times can be perfomed over tools such as LoadStorm , JMeter.
Alternatively use websoscket like setup inplace of non reusable TCP connection like HTTP or polling to set up signalling.
Bandwidth can be estmated by
RTCP Receiver Reports which periodically summary to indicate packet loss rate and jitter etc from receiver.
TWCC (Transport Wide congestion Control ) calculates the intra-packet delays to estimate the Sender Side Bandwidth
REMB( Receiver Side Bandwidth Estimation) provide bandwidth estimation by measuing the packet loss
- used to configure the bitrate in video encoding
- used to avoid congestion or slow media transmission
As a communication agent become a single HTML page driven client, a lot of authentication, heartbeat sync, web workers, signalling event-driven flow management resides on the same page along with the actual CPU consumption for the audio-video resources and media streams processing. This in turn can make the webpage heavy and many a time could result in a crash due to being ” unresponsive”.
Here are some my best to-dos for making sure the webrtc communication client page runs efficiently
CLS metrics measures the sum total of all individual layout shift scores for every unexpected layout shift that occurs during the entire lifespan of the page.
To have a good user interactionn experiences, the DOM elements should display as less movement as possible so that page appears stable . In the opposite case for a flickering page ( maybe due to notification DOM dynamically pushing the other layout elements ) it is difficult to precisely interact with the page elements such as buttons .
Deprication of XMLHTTP request on main thread
Unoptimized JS code takes longer to execute and impacts network , parse-compileand memory cost.
Some effective tips to spedding up JS execution include
- minifying and compressing code
- Removing the unused code and console.logs
- Apply caching to save lookup time
Cross-site request forgery (CSRF) attacks rely on the fact that cookies are attached to any request to a given origin, no matter who initiates the request.
While adding cookies we must ensure that if SameSite =None , the cookies must be secure
Set-Cookie: widget_session=abc123; SameSite=None; Secure
Strict, your cookie will only be sent in a first-party context. In user terms, the cookie will only be sent if the site for the cookie matches the site currently shown in the browser’s URL bar.
Set-Cookie: promo_shown=1; SameSite=Strict
You can test this behavior as of Chrome 76 by enabling
chrome://flags/#cookies-without-same-site-must-be-secure and from Firefox 69 in
about:config by setting
Key Performance Indicators (KPIs) are used to evaluate the performance of a website . It is crticial that a webrtc web page must be light weight to acocmodate the signalling control stack javscript libs to be used for offer answer handling and communicating with the signaller on open sockets or long polling mechnism .
Lighthouse tab in chrome developer tools shows relavnat areas of imporevemnt on the webpage from performmace , Accesibility , Best Practices , Search Engine optimization and progressive Web App
Also shsows individual categories and comments
Page attributes under Chrome developers control depicts the page load and redering time for every element includeing scripts and markup. Specifically it has
- Time to Title
- Time to render
- Time to inetract
Networking attributes to be cofigured based on DNS mapping and host provider. These Can be evalutaed based on chrome developer tool reports
Other page interaction crtiteria includes the frames their inetraction and timings for the same.
In the screenhosta ttcjed see the loading tasks which basically depcits the delay by dom elements under transitions owing to user interaction . This ideally should be minimum to keep the page responsive.
The above functions ( old and new ) estimates the memory usage of the entire web page
these calls can be used to correlate new JS code with the impact on memery and subsewuntly find if there are any memeory leaks. Can also use these memery metrics to do A/B testing .
Loading assests over CDN , minfying sripts and reducing over all weight of the page are good ways to keep the page light and active and prevent any chrome tab crashes.
PRPL expands to Push/preload , Render , PreCache , Lazy load
- Render the initial route as soon as possible.
- Pre-cache remaining assets.
- Lazy load other routes and non-critical assets.
Preload is a declarative fetch request that tells the browser to request a resource as soon as possible. Hence should be used for crticial assests .
<link rel="preload" as="script" href="critical.js">
The non critical compoenents could then be loaded on async .
Web Workers are a simple means for web content to run scripts in background threads.The
Worker interface spawns real OS-level threads
By acting as a proxy, service workers can fetch assets directly from the cache rather than the server on repeat visits.
Threads and Cores
- CLS – https://web.dev/cls/?utm_source=devtools
- Cookies – https://web.dev/samesite-cookies-explained/
- JS execution time – https://web.dev/bootup-time/?utm_source=lighthouse&utm_medium=devtools