diff options
| author | Stephen Blott | 2016-04-02 06:51:56 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2016-04-02 06:51:59 +0100 | 
| commit | a51f18c04d28b77e7cc2728c0cb85a2b2998ef54 (patch) | |
| tree | d4576347f4134e35e33af7c5db9e8c05983a150d | |
| parent | 64d8c34a628d142400abb8f417a1f9d48220e60c (diff) | |
| download | vimium-a51f18c04d28b77e7cc2728c0cb85a2b2998ef54.tar.bz2 | |
Use port for frame-to-background messages.
Without considering the size of the data passed, ports seem to be about
5 times fast than sendMessage(), so we use ports of link-hint messages
wherever possible.
| -rw-r--r-- | background_scripts/main.coffee | 7 | ||||
| -rw-r--r-- | content_scripts/link_hints.coffee | 4 | 
2 files changed, 10 insertions, 1 deletions
| diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 663871de..107edc45 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -335,6 +335,9 @@ Frames =    initializeTopFrameUIComponents: ({tabId}) ->      portsForTab[tabId][0]?.postMessage handler: "initializeTopFrameUIComponents" +  linkHintsMessage: ({request, tabId, frameId}) -> +    HintCoordinator.onMessage extend(request, {frameId}), tab: id: tabId +  handleFrameFocused = ({tabId, frameId}) ->    frameIdsForTab[tabId] ?= []    frameIdsForTab[tabId] = cycleToFrame frameIdsForTab[tabId], frameId @@ -351,6 +354,10 @@ cycleToFrame = (frames, frameId, count = 0) ->  HintCoordinator =    tabState: {} +  # These messages can be received via sendRequestHandlers or via a Frames port.  The Frames port seems to be +  # considerably faster (about a factor of 5), so we use that whenever possible.  However, when sending +  # messages, we use chrome.tabs.sendMessage because, in tabs with many frames, broadcasting seems (?) likely +  # to be faster.    onMessage: (request, {tab: {id: tabId}}) ->      if request.messageType of this        this[request.messageType] tabId, request diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index af29b435..d22657ad 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -53,7 +53,9 @@ HintCoordinator =    onExit: []    sendMessage: (messageType, request = {}) -> -    chrome.runtime.sendMessage extend request, {handler: "linkHintsMessage", messageType, frameId} +    # We use Frame.postMessage() (instead of chrome.runtime.sendMessage()) because that seems to be +    # considerable faster, by about a factor of 5. +    Frame.postMessage "linkHintsMessage", extend request, {messageType}    prepareToActivateMode: (mode, onExit) ->      # We need to communicate with the background page (and other frames) to initiate link-hints mode.  To | 
