]> git.kaiwu.me - nginx.git/commitdiff
QUIC: optimize insertion at the end of QUIC buffer.
authorRoman Arutyunyan <arut@nginx.com>
Mon, 14 Feb 2022 11:54:34 +0000 (14:54 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Mon, 14 Feb 2022 11:54:34 +0000 (14:54 +0300)
src/event/quic/ngx_event_quic.h
src/event/quic/ngx_event_quic_frames.c

index 8f6dd7e78f67431ff21c2b87c65f90ddb669c152..109cd54ef12a2316d5991872045e2ff87e6ed6e2 100644 (file)
@@ -51,7 +51,9 @@ typedef enum {
 typedef struct {
     uint64_t                       size;
     uint64_t                       offset;
+    uint64_t                       last_offset;
     ngx_chain_t                   *chain;
+    ngx_chain_t                  **last_chain;
 } ngx_quic_buffer_t;
 
 
index c6d8de74e04f3d1f0dc62bce23378190c55923b6..5ffae32c30beead500988c5a795e1c91ad388446 100644 (file)
@@ -421,6 +421,10 @@ ngx_quic_read_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb, uint64_t limit)
         qb->offset += n;
     }
 
+    if (qb->offset >= qb->last_offset) {
+        qb->last_chain = NULL;
+    }
+
     qb->chain = *ll;
     *ll = NULL;
 
@@ -462,6 +466,10 @@ ngx_quic_skip_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb,
     if (qb->chain == NULL) {
         qb->offset = offset;
     }
+
+    if (qb->offset >= qb->last_offset) {
+        qb->last_chain = NULL;
+    }
 }
 
 
@@ -493,8 +501,14 @@ ngx_quic_write_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb,
     ngx_buf_t    *b;
     ngx_chain_t  *cl, **chain;
 
-    base = qb->offset;
-    chain = &qb->chain;
+    if (qb->last_chain && offset >= qb->last_offset) {
+        base = qb->last_offset;
+        chain = qb->last_chain;
+
+    } else {
+        base = qb->offset;
+        chain = &qb->chain;
+    }
 
     while (in && limit) {
 
@@ -585,6 +599,9 @@ ngx_quic_write_buffer(ngx_connection_t *c, ngx_quic_buffer_t *qb,
         }
     }
 
+    qb->last_offset = base;
+    qb->last_chain = chain;
+
     return in;
 }