aboutsummaryrefslogtreecommitdiffstats
path: root/js/vapi-background.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/vapi-background.js')
-rw-r--r--js/vapi-background.js66
1 files changed, 0 insertions, 66 deletions
diff --git a/js/vapi-background.js b/js/vapi-background.js
index 6c874f3..0da0638 100644
--- a/js/vapi-background.js
+++ b/js/vapi-background.js
@@ -69,72 +69,6 @@
}
};
- let CallbackWrapper = function (messageManager, channelName,
- listenerId, requestId) {
- // This allows to avoid creating a closure for every single
- // message which expects an answer. Having a closure created
- // each time a message is processed has been always bothering
- // me. Another benefit of the implementation here is to reuse
- // the callback proxy object, so less memory churning.
- //
- // https://developers.google.com/speed/articles/optimizing-javascript
- // "Creating a closure is significantly slower then creating
- // an inner function without a closure, and much slower than
- // reusing a static function"
- //
- // http://hacksoflife.blogspot.ca/2015/01/the-four-horsemen-of-performance.html
- // "the dreaded 'uniformly slow code' case where every
- // function takes 1% of CPU and you have to make one hundred
- // separate performance optimizations to improve performance
- // at all"
- //
- // http://jsperf.com/closure-no-closure/2
- this.callback = this.proxy.bind(this); // bind once
- this.init(messageManager, channelName, listenerId, requestId);
- };
-
- CallbackWrapper.junkyard = [];
-
- CallbackWrapper.factory = function (messageManager, channelName,
- listenerId, requestId) {
- let wrapper = CallbackWrapper.junkyard.pop();
- if (wrapper) {
- wrapper.init(messageManager, channelName, listenerId, requestId);
- return wrapper;
- }
-
- return new CallbackWrapper(messageManager, channelName,
- listenerId, requestId);
- };
-
- CallbackWrapper.prototype.init = function (messageManager, channelName,
- listenerId, requestId) {
- this.messageManager = messageManager;
- this.channelName = channelName;
- this.listenerId = listenerId;
- this.requestId = requestId;
- };
-
- CallbackWrapper.prototype.proxy = function (response) {
- let message = JSON.stringify({
- requestId: this.requestId,
- channelName: this.channelName,
- msg: response !== undefined ? response : null
- });
-
- if (this.messageManager.sendAsyncMessage) {
- this.messageManager.sendAsyncMessage(this.listenerId, message);
- } else {
- this.messageManager.broadcastAsyncMessage(this.listenerId, message);
- }
-
- // Mark for reuse
- this.messageManager = this.channelName =
- this.requestId = this.listenerId = null;
-
- CallbackWrapper.junkyard.push(this);
- };
-
let httpRequestHeadersFactory = function (channel) {
let entry = httpRequestHeadersFactory.junkyard.pop();
if (entry) {