[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/websocket ff566c4ad7 077/114: Fix some performance bott
From: |
ELPA Syncer |
Subject: |
[elpa] externals/websocket ff566c4ad7 077/114: Fix some performance bottlenecks. |
Date: |
Wed, 15 Feb 2023 20:59:01 -0500 (EST) |
branch: externals/websocket
commit ff566c4ad7539e5f220772bca1977d859cee72ef
Author: Andrew Hyatt <ahyatt@gmail.com>
Commit: Andrew Hyatt <ahyatt@gmail.com>
Fix some performance bottlenecks.
Notably, `websocket-mask' was somewhat slow due to inefficient
implementation, and
use of `websocket-get-bytes' wasn't nearly as fast as aref for 1-byte
sequences.
---
websocket.el | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/websocket.el b/websocket.el
index ffd22f4e73..53ec1dd25c 100644
--- a/websocket.el
+++ b/websocket.el
@@ -217,7 +217,7 @@ approximately 537M long."
"websocket-get-bytes: Unknown N: %S" n)))))
s)
(args-out-of-range (signal 'websocket-unparseable-frame
- (list (format "Frame unexpectedly shortly:
%s" s)))))
+ (list (format "Frame unexpectedly short: %s"
s)))))
:val)))
(defun websocket-to-bytes (val nbytes)
@@ -252,7 +252,7 @@ approximately 537M long."
(defun websocket-get-opcode (s)
"Retrieve the opcode from first byte of string S."
(websocket-ensure-length s 1)
- (let ((opcode (logand #xf (websocket-get-bytes s 1))))
+ (let ((opcode (logand #xf (aref s 0))))
(cond ((= opcode 0) 'continuation)
((= opcode 1) 'text)
((= opcode 2) 'binary)
@@ -265,7 +265,7 @@ approximately 537M long."
We start at position 0, and return a cons of the payload length and how
many bytes were consumed from the string."
(websocket-ensure-length s 1)
- (let* ((initial-val (logand 127 (websocket-get-bytes s 1))))
+ (let* ((initial-val (logand 127 (aref s 0))))
(cond ((= initial-val 127)
(websocket-ensure-length s 9)
(cons (websocket-get-bytes (substring s 1) 8) 9))
@@ -289,12 +289,15 @@ This is used to both mask and unmask data."
;; string of the same length (for example, 6 multibyte chars for 你好 instead
;; of the correct 6 unibyte chars, which would convert into 2 multibyte
;; chars).
- (apply
- #'unibyte-string
- (cl-loop for b across data
- for i from 0 to (length data)
- collect
- (logxor (websocket-get-bytes (substring key (mod i 4)) 1) b))))
+ (funcall
+ #'encode-coding-string
+ (let ((result (make-string (length data) ?x)))
+ (cl-loop
+ for i from 0 below (length data)
+ do
+ (setf (seq-elt result i) (logxor (aref key (mod i 4)) (seq-elt data i)))
+ finally (return result)))
+ 'utf-8))
(defun websocket-ensure-length (s n)
"Ensure the string S has at most N bytes.
@@ -351,13 +354,13 @@ the frame finishes. If the frame is not completed,
return NIL."
(catch 'websocket-incomplete-frame
(websocket-ensure-length s 1)
(let* ((opcode (websocket-get-opcode s))
- (fin (logand 128 (websocket-get-bytes s 1)))
+ (fin (logand 128 (aref s 0)))
(payloadp (memq opcode '(continuation text binary ping pong)))
(payload-len (when payloadp
(websocket-get-payload-len (substring s 1))))
(maskp (and
payloadp
- (= 128 (logand 128 (websocket-get-bytes (substring s 1)
1)))))
+ (= 128 (logand 128 (aref s 1)))))
(payload-start (when payloadp (+ (if maskp 5 1) (cdr payload-len))))
(payload-end (when payloadp (+ payload-start (car payload-len))))
(unmasked-payload (when payloadp
- [elpa] externals/websocket 23ec19933d 050/114: Various idiomatic changes., (continued)
- [elpa] externals/websocket 23ec19933d 050/114: Various idiomatic changes., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 99d3b3e695 053/114: need another sleep on my environment, ELPA Syncer, 2023/02/15
- [elpa] externals/websocket c193d6f867 058/114: Add ability for clients to pass custom headers., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 058e8f4696 059/114: Fix issue with missing \r\n when using custom headers., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 7d2adf2187 061/114: Update version to 1.9., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket d28b6b4633 065/114: ensure handshake is performed, ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 38c1f20cb3 066/114: ensure handshake called once, ELPA Syncer, 2023/02/15
- [elpa] externals/websocket d34f5f095d 070/114: Update version to 1.10., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 71f2290962 073/114: Delete .DS_Store, ELPA Syncer, 2023/02/15
- [elpa] externals/websocket d8ef1b764a 074/114: Merge pull request #55 from raxod502/patch-1, ELPA Syncer, 2023/02/15
- [elpa] externals/websocket ff566c4ad7 077/114: Fix some performance bottlenecks.,
ELPA Syncer <=
- [elpa] externals/websocket 6369b4fc48 080/114: return value of websocket-mask needs to be unibyte, ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 37ef222d62 082/114: Stop converting the webmask to unibyte., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket c4f17b1b70 090/114: Add `'run` to handshake status, ELPA Syncer, 2023/02/15
- [elpa] externals/websocket ee44af2cc5 092/114: Merge pull request #65 from yuya373/fix-handshake-when-nowait, ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 31bb007b98 098/114: introduce configurable wstest-server-url, ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 5568114781 105/114: Make sure unit tests don't cause problems on 32-bit systems., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket d46cacb8b1 007/114: Add back in calling of websocket-close, this time more safely., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 43bbf7b32f 019/114: Bump version to 1.3., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket e5cd7c9557 026/114: Bump version to 1.5., ELPA Syncer, 2023/02/15
- [elpa] externals/websocket 19f9b3b74f 037/114: Merge pull request #44 from chwarr/websocket-server-host, ELPA Syncer, 2023/02/15