Procházet zdrojové kódy

Fetch browser subresources in parallel

Download stylesheet and external-script bodies with up to four helper workers, then parse stylesheets and execute scripts in document order so the cascade and script ordering stay unchanged.

Start one above-fold image before the script phase; the remaining image downloads resume with all workers once the scripts finish.  Track image jobs separately from foreground fetches so the worker budget applies only to the preloader.

Raise FETCH_WORKERS to four and update AGENTS.md and the architecture pages.
Johannes Zellner před 1 týdnem
rodič
revize
5e4bf596a1
4 změnil soubory, kde provedl 340 přidání a 65 odebrání
  1. 10 5
      AGENTS.md
  2. 327 57
      browser.c
  3. 1 1
      docs/network.html
  4. 2 2
      docs/userland.html

+ 10 - 5
AGENTS.md

@@ -1005,15 +1005,18 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   so later visits to a bare domain go straight to its canonical scheme/host.
   Remote stylesheets are cached under `/share/bcss-*` for the current boot, so
   a reload or a fresh browser launch does not fetch the same CSS sheets again.
-  Images are prefetched up to three at a time and only when their measured
+  Images are prefetched up to four at a time and only when their measured
   position is within the viewport plus 160 px; deferred images are loaded as
-  the page scrolls.  Network work runs in up to `FETCH_WORKERS` (three)
+  the page scrolls.  Network work runs in up to `FETCH_WORKERS` (four)
   headless `curl __serve` helper processes (`ucmd_curl.c`), each with its own
   `/share/bf<session>_<slot>*` files (`session` comes from the browser pid, so
   two browser windows cannot collide).  The browser
   starts jobs, harvests completed ones from its main loop and decodes them,
   so text and scrolling stay responsive while several TCP/TLS connections are
-  in flight; page/CSS/script fetches stay ordered.  Each helper keeps its own
+  in flight.  Stylesheet and external-script bodies are downloaded in parallel
+  but parsed/executed in document order; one above-fold image starts downloading
+  before the script phase so it overlaps the script fetches and execution.
+  Each helper keeps its own
   TCP/TLS connection (TLS stays per-process).  Idle helpers stay warm across
   navigations so a second page on the same origin reuses the TCP/TLS
   connection instead of paying a spawn and handshake; they exit after ten
@@ -1847,10 +1850,12 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     cached bitmap on every repaint.  Lazy
     image loading uses the last measured positions; adding an image can
     reflow the content above it, and images below the viewport stay as
-    `[image]` until scrolled into range.  The browser keeps up to three
+    `[image]` until scrolled into range.  The browser keeps up to four
     `curl __serve` workers, each with its own TCP/TLS keep-alive connection
     and private `/share/bf*N` files; images are prefetched in parallel and
-    decoded as jobs complete.  Page/CSS/script fetches stay ordered.  Idle
+    decoded as jobs complete.  Stylesheet and external-script bodies are
+    downloaded in parallel but parsed/executed in document order, and one
+    image starts before the script phase.  Idle
     helpers stay warm across navigations and are stopped when the browser
     loses focus (or after ten idle seconds) so their sockets do not block raw
     commands.  The helper requests gzip; a page

+ 327 - 57
browser.c

@@ -104,6 +104,7 @@ static struct br_layout_box layout_boxes[BR_MAX_NODES];
 /* Images are loaded one per main-loop iteration so the parsed page stays
  * interactive while a slow network/TLS fetch or 4K decode is in progress. */
 static int preload_active;
+static int preload_max_jobs;
 static int preload_pending;
 static int preload_wait;
 static unsigned int preload_node;
@@ -1098,6 +1099,27 @@ static int fetch_script_text(const char *url, unsigned char **out,
 			     unsigned int *outlen, char *err,
 			     unsigned int errcap);
 
+struct fetch_worker;
+static struct fetch_worker *fetch_worker_alloc(void);
+static void fetch_worker_release(struct fetch_worker *w);
+static int fetch_worker_submit(struct fetch_worker *w, const char *url,
+			       unsigned int cap, const char *post,
+			       unsigned int post_len, unsigned int node,
+			       int bg, char *err, unsigned int errcap);
+static int fetch_worker_wait(struct fetch_worker *w, char *err,
+			     unsigned int errcap);
+static int fetch_worker_read_body(struct fetch_worker *w,
+				  unsigned char *plain,
+				  unsigned int plaincap,
+				  unsigned char *comp,
+				  unsigned int compcap,
+				  int *truncated, char *err,
+				  unsigned int errcap);
+static void fetch_workers_stop_all(void);
+static int script_cache_has(const char *url);
+static void script_cache_put(const char *url, const unsigned char *data,
+			     unsigned int len);
+
 static void script_error(const char *what, const char *url, const char *why)
 {
 	char msg[192];
@@ -1115,12 +1137,51 @@ static void script_error(const char *what, const char *url, const char *why)
 	js_host_report(msg);
 }
 
-/* Run the page's scripts in document order: external <script src> bodies are
- * fetched, inline bodies are copied because MuJS needs NUL-terminated text. */
+/* Script prefetch state: one entry per <script> block.  Remote bodies are
+ * submitted to helper workers ahead of time, but scripts still execute in
+ * document order. */
+#define SCRIPT_INLINE 0
+#define SCRIPT_LOCAL  1
+#define SCRIPT_REMOTE 2
+#define SCRIPT_ERROR  3
+
+static char script_urls[BR_MAX_SCRIPTS][BR_URL_MAX];
+static unsigned char script_kind[BR_MAX_SCRIPTS];
+static struct fetch_worker *script_slot[BR_MAX_SCRIPTS];
+
+static void script_submit_window(unsigned int *next, char *err,
+				 unsigned int errcap)
+{
+	while (*next < doc.nscripts) {
+		struct fetch_worker *w;
+
+		if (script_kind[*next] != SCRIPT_REMOTE) {
+			(*next)++;
+			continue;
+		}
+		w = fetch_worker_alloc();
+		if (!w)
+			return;
+		if (fetch_worker_submit(w, script_urls[*next], BR_SCRIPT_MAX,
+					0, 0, 0, 0, err, errcap) != 0) {
+			fetch_worker_release(w);
+			script_kind[*next] = SCRIPT_ERROR;
+			(*next)++;
+			continue;
+		}
+		script_slot[*next] = w;
+		(*next)++;
+	}
+}
+
+/* Run the page's scripts in document order.  External bodies are prefetched
+ * in parallel so downloading script N+1 overlaps executing script N; inline
+ * bodies are copied because MuJS needs NUL-terminated text. */
 static void run_page_scripts(void)
 {
 	struct js_browser_host host;
-	unsigned int i;
+	unsigned int i, next = 0;
+	char err[64], ferr[64];
 
 	if (!doc.nscripts)
 		return;
@@ -1147,37 +1208,36 @@ static void run_page_scripts(void)
 		js_host_status("JavaScript: out of memory", 1);
 		return;
 	}
+
 	for (i = 0; i < doc.nscripts; i++) {
 		struct br_script *script = &doc.scripts[i];
+		const char *src_attr = script->src_off ?
+			doc.attrs + script->src_off : "";
 
-		if (script->src_off) {
-			const char *src_attr = doc.attrs + script->src_off;
-			char url[BR_URL_MAX];
-			unsigned char *data;
-			unsigned int len;
-			char err[64];
-			int rv;
+		script_slot[i] = 0;
+		if (!script->src_off) {
+			script_kind[i] = SCRIPT_INLINE;
+			continue;
+		}
+		if (!src_attr[0] ||
+		    resolve_link(page_url, src_attr, script_urls[i],
+				 sizeof(script_urls[i])) != 0) {
+			script_urls[i][0] = '\0';
+			script_kind[i] = SCRIPT_ERROR;
+			continue;
+		}
+		if (script_urls[i][0] == '/' ||
+		    script_cache_has(script_urls[i]))
+			script_kind[i] = SCRIPT_LOCAL;
+		else
+			script_kind[i] = SCRIPT_REMOTE;
+	}
+	script_submit_window(&next, ferr, sizeof(ferr));
 
-			if (!src_attr[0])
-				continue;
-			if (resolve_link(page_url, src_attr, url,
-					 sizeof(url)) != 0) {
-				script_error("Cannot load script", src_attr,
-					     "unsupported URL");
-				continue;
-			}
-			set_status("Loading script...", 0, 0);
-			rv = fetch_script_text(url, &data, &len, err,
-					       sizeof(err));
-			if (rv == FETCH_ABORT)
-				break;
-			if (rv != 0) {
-				script_error("Cannot load script", url, err);
-				continue;
-			}
-			js_browser_run((const char *)data, url);
-			free(data);
-		} else {
+	for (i = 0; i < doc.nscripts; i++) {
+		struct br_script *script = &doc.scripts[i];
+
+		if (script_kind[i] == SCRIPT_INLINE) {
 			unsigned int off = script->off;
 			unsigned int len = script->len;
 			unsigned int k;
@@ -1192,6 +1252,92 @@ static void run_page_scripts(void)
 			src[len] = '\0';
 			js_browser_run(src, page_url);
 			free(src);
+		} else if (script->src_off) {
+			const char *src_attr = doc.attrs + script->src_off;
+
+			if (script_kind[i] == SCRIPT_ERROR) {
+				script_error("Cannot load script", src_attr,
+					     script_urls[i][0] ?
+					     "network busy" :
+					     "unsupported URL");
+				continue;
+			}
+			if (script_kind[i] == SCRIPT_LOCAL) {
+				unsigned char *data = 0;
+				unsigned int len = 0;
+				int rv;
+
+				set_status("Loading script...", 0, 0);
+				rv = fetch_script_text(script_urls[i], &data,
+						       &len, err, sizeof(err));
+				if (rv == FETCH_ABORT)
+					break;
+				if (rv != 0) {
+					script_error("Cannot load script",
+						     script_urls[i], err);
+					continue;
+				}
+				js_browser_run((const char *)data,
+					       script_urls[i]);
+				free(data);
+			} else {
+				struct fetch_worker *w = script_slot[i];
+				int tr = 0, rv;
+
+				if (!w) {
+					w = fetch_worker_alloc();
+					if (!w)
+						continue;
+					if (fetch_worker_submit(w,
+							script_urls[i],
+							BR_SCRIPT_MAX,
+							0, 0, 0, 0, err,
+							sizeof(err)) != 0) {
+						fetch_worker_release(w);
+						script_kind[i] = SCRIPT_ERROR;
+						if (i == next)
+							next++;
+						continue;
+					}
+					script_slot[i] = w;
+					if (i == next)
+						next++;
+				}
+				set_status("Loading script...", 0, 0);
+				rv = fetch_worker_wait(w, err, sizeof(err));
+				if (rv == FETCH_ABORT) {
+					fetch_workers_stop_all();
+					break;
+				}
+				if (rv == 0)
+					rv = fetch_worker_read_body(w,
+						image_io_buf, BR_SCRIPT_MAX,
+						image_io_buf + BR_SCRIPT_MAX,
+						BR_IMG_FILE_MAX, &tr, err,
+						sizeof(err));
+				else
+					rv = -1;
+				fetch_worker_release(w);
+				script_slot[i] = 0;
+				script_submit_window(&next, ferr, sizeof(ferr));
+				if (rv <= 0)
+					script_error("Cannot load script",
+						     script_urls[i], err);
+				else if (tr || (unsigned int)rv >=
+					 BR_SCRIPT_MAX)
+					script_error("Cannot load script",
+						     script_urls[i],
+						     "script is too large");
+				else {
+					image_io_buf[rv] = '\0';
+					script_cache_put(script_urls[i],
+							 image_io_buf,
+							 (unsigned int)rv);
+					js_browser_run(
+						(const char *)image_io_buf,
+						script_urls[i]);
+				}
+			}
 		}
 		if (pending_action)
 			break;
@@ -1790,7 +1936,7 @@ struct fetch_meta {
 static void draw(unsigned int *action);
 static void handle_keys(unsigned int *action);
 static void handle_page_click(unsigned int *action);
-#define FETCH_WORKERS 3
+#define FETCH_WORKERS 4
 #define FETCH_PATH_MAX 32
 
 /* One long-lived curl __serve helper per worker.  Each worker has its own
@@ -1802,6 +1948,7 @@ struct fetch_worker {
 	int slot;
 	int busy;
 	int ready;
+	int image_job;
 	unsigned int seq;
 	unsigned int deadline;
 	int retried;
@@ -1930,6 +2077,7 @@ static void fetch_worker_stop(struct fetch_worker *w)
 	w->pid = -1;
 	w->busy = 0;
 	w->ready = 0;
+	w->image_job = 0;
 	if (w->req[0]) {
 		u_syscall1(SYS_UNLINK, (int)w->done);
 		u_syscall1(SYS_UNLINK, (int)w->meta);
@@ -2026,6 +2174,7 @@ static int fetch_worker_submit(struct fetch_worker *w, const char *url,
 		fetch_seq = 1;
 	w->seq = fetch_seq;
 	w->ready = 0;
+	w->image_job = 0;
 	w->retried = 0;
 	w->m.error = 0;
 	w->node = node;
@@ -2209,6 +2358,7 @@ static void fetch_worker_release(struct fetch_worker *w)
 	u_syscall1(SYS_UNLINK, (int)w->req);
 	w->busy = 0;
 	w->ready = 0;
+	w->image_job = 0;
 }
 
 /* Blocking wait used by page/CSS/script fetches; keeps the UI alive. */
@@ -2506,6 +2656,16 @@ static void script_cache_put(const char *url, const unsigned char *data,
 		script_cache_count++;
 }
 
+static int script_cache_has(const char *url)
+{
+	char path[96];
+	struct sys_stat st;
+
+	script_cache_path(url, path, sizeof(path));
+	return u_stat(path, &st) == 0 && !st.is_dir && st.size > 0 &&
+	       st.size < SCRIPT_CACHE_FILE_MAX;
+}
+
 /* Fetch one external script into a heap buffer and NUL-terminate it. */
 static int fetch_script_text(const char *url, unsigned char **out,
 			     unsigned int *outlen, char *err,
@@ -2679,6 +2839,16 @@ static void css_cache_put(const char *url, const unsigned char *data,
 		css_cache_count++;
 }
 
+static int css_cache_has(const char *url)
+{
+	char path[96];
+	struct sys_stat st;
+
+	css_cache_path(url, path, sizeof(path));
+	return u_stat(path, &st) == 0 && !st.is_dir && st.size > 0 &&
+	       st.size < CSS_CACHE_FILE_MAX;
+}
+
 /* Read one stylesheet into the shared static buffer.  CSS is parsed
  * immediately, so it does not need the page heap; this leaves the heap for
  * the 2 MB page body, the rules and the scaled image bitmaps. */
@@ -2785,19 +2955,21 @@ static int ancestor_is(unsigned int node, unsigned int tag)
 	return 0;
 }
 
+/* Fetch and parse the page's stylesheets.  Remote bodies are downloaded in
+ * parallel but parsed in document order, so the cascade is unchanged. */
 static int load_stylesheets(void)
 {
-	static char seen[BR_MAX_SHEETS][BR_URL_MAX];
-	unsigned int i, sheets = 0, nseen = 0;
+	static char urls[BR_MAX_SHEETS][BR_URL_MAX];
+	static unsigned char remote[BR_MAX_SHEETS];
+	struct fetch_worker *slot[BR_MAX_SHEETS];
+	unsigned int i, n = 0, next = 0, k;
+	char err[64];
 
-	for (i = 0; i < doc.nnode && sheets < BR_MAX_SHEETS; i++) {
+	for (i = 0; i < doc.nnode && n < BR_MAX_SHEETS; i++) {
 		struct br_node *nd = &doc.nodes[i];
 		const char *rel, *href;
 		char url[BR_URL_MAX];
-		unsigned char *data;
-		unsigned int len;
-		char err[64];
-		int rv;
+		int dup = 0;
 
 		if (nd->type != BR_NODE_ELEM || nd->tag != BR_TAG_LINK)
 			continue;
@@ -2809,32 +2981,117 @@ static int load_stylesheets(void)
 			continue;
 		if (resolve_link(page_url, href, url, sizeof(url)) != 0)
 			continue;
-		{
-			unsigned int k;
-			int dup = 0;
+		for (k = 0; k < n; k++)
+			if (s_eq(urls[k], url)) {
+				dup = 1;
+				break;
+			}
+		if (dup)
+			continue;
+		s_copy(urls[n], url, BR_URL_MAX);
+		remote[n] = url[0] != '/' && !css_cache_has(url);
+		n++;
+	}
+
+	for (i = 0; i < BR_MAX_SHEETS; i++)
+		slot[i] = 0;
+
+	/* Start as many remote sheets as there are free workers. */
+	for (; next < n; next++) {
+		struct fetch_worker *w;
+
+		if (!remote[next])
+			continue;
+		w = fetch_worker_alloc();
+		if (!w)
+			break;
+		if (fetch_worker_submit(w, urls[next], BR_CSS_MAX, 0, 0, 0, 0,
+					err, sizeof(err)) != 0) {
+			fetch_worker_release(w);
+			remote[next] = 0;
+			continue;
+		}
+		slot[next] = w;
+	}
+
+	for (i = 0; i < n; i++) {
+		unsigned char *data = 0;
+		unsigned int len = 0;
+		int rv;
 
-			for (k = 0; k < nseen; k++)
-				if (s_eq(seen[k], url)) {
-					dup = 1;
+		if (!remote[i]) {
+			rv = fetch_css(urls[i], &data, &len, err, sizeof(err));
+			if (rv == FETCH_ABORT) {
+				fetch_workers_stop_all();
+				return FETCH_ABORT;
+			}
+			if (rv != 0 || !len)
+				continue;
+		} else {
+			struct fetch_worker *w = slot[i];
+			int tr = 0;
+
+			if (!w) {
+				w = fetch_worker_alloc();
+				if (!w)
+					continue;
+				if (fetch_worker_submit(w, urls[i], BR_CSS_MAX,
+							0, 0, 0, 0, err,
+							sizeof(err)) != 0) {
+					fetch_worker_release(w);
+					remote[i] = 0;
+					if (i == next)
+						next++;
+					continue;
+				}
+				slot[i] = w;
+				if (i == next)
+					next++;
+			}
+			rv = fetch_worker_wait(w, err, sizeof(err));
+			if (rv == FETCH_ABORT) {
+				fetch_workers_stop_all();
+				return FETCH_ABORT;
+			}
+			if (rv == 0)
+				rv = fetch_worker_read_body(w, image_io_buf,
+						BR_CSS_MAX,
+						image_io_buf + BR_CSS_MAX,
+						BR_CSS_COMP_MAX, &tr,
+						err, sizeof(err));
+			else
+				rv = -1;
+			fetch_worker_release(w);
+			slot[i] = 0;
+
+			/* Refill the worker window before parsing this sheet. */
+			for (; next < n; next++) {
+				struct fetch_worker *nw;
+
+				if (!remote[next])
+					continue;
+				nw = fetch_worker_alloc();
+				if (!nw)
 					break;
+				if (fetch_worker_submit(nw, urls[next],
+						BR_CSS_MAX, 0, 0, 0, 0,
+						err, sizeof(err)) != 0) {
+					fetch_worker_release(nw);
+					remote[next] = 0;
+					continue;
 				}
-			if (dup)
-				continue;
-			if (nseen < BR_MAX_SHEETS) {
-				s_copy(seen[nseen], url, BR_URL_MAX);
-				nseen++;
+				slot[next] = nw;
 			}
+			if (rv <= 0)
+				continue;
+			len = (unsigned int)rv;
+			data = image_io_buf;
+			css_cache_put(urls[i], data, len);
 		}
-		rv = fetch_css(url, &data, &len, err, sizeof(err));
-		if (rv == FETCH_ABORT)
-			return FETCH_ABORT;
-		if (rv != 0)
-			continue;
 		if (len) {
-			br_set_font_base(url);
+			br_set_font_base(urls[i]);
 			br_parse_css_text(&doc, (const char *)data, len);
 		}
-		sheets++;
 	}
 	br_set_font_base(page_url);
 	br_parse_inline_css(&doc);
@@ -2849,6 +3106,7 @@ static void preload_begin(void)
 	preload_active = 1;
 	preload_pending = 0;
 	preload_wait = 1;
+	preload_max_jobs = FETCH_WORKERS;
 	preload_node = 0;
 	preload_loaded = 0;
 	preload_scroll = 0;
@@ -2908,7 +3166,7 @@ static int preload_active_jobs(void)
 	int i, n = 0;
 
 	for (i = 0; i < FETCH_WORKERS; i++)
-		if (fetch_workers[i].busy)
+		if (fetch_workers[i].busy && fetch_workers[i].image_job)
 			n++;
 	return n;
 }
@@ -2992,6 +3250,9 @@ static int preload_fill_jobs(void)
 		char url[BR_URL_MAX];
 		struct fetch_worker *w;
 
+		if (preload_active_jobs() >= preload_max_jobs)
+			break;
+
 		if (nd->type != BR_NODE_ELEM) {
 			preload_node++;
 			continue;
@@ -3046,6 +3307,7 @@ static int preload_fill_jobs(void)
 							fetch_worker_release(w);
 							continue;
 						}
+						w->image_job = 1;
 						started++;
 						continue;
 					}
@@ -3122,6 +3384,7 @@ static int preload_fill_jobs(void)
 			fetch_worker_release(w);
 			continue;
 		}
+		w->image_job = 1;
 		started++;
 	}
 	return started;
@@ -3347,7 +3610,14 @@ static void load_page(const char *url, int local, int push)
 	 * screen; the fetch helper pumps this UI while it waits. */
 	set_status("Loading scripts...", 0, 0);
 	redraw_now();
+	/* Start one image download before the scripts.  The other workers
+	 * fetch the external script bodies in parallel, and the remaining
+	 * images start as soon as the script phase ends. */
+	preload_max_jobs = 1;
+	preload_fill_jobs();
+	preload_wait = 0;
 	run_page_scripts();
+	preload_max_jobs = FETCH_WORKERS;
 	if (pending_action)
 		return;
 

+ 1 - 1
docs/network.html

@@ -390,7 +390,7 @@
 			<li><strong>curl</strong> — <code>http://</code> or <code>https://</code> GET with DNS, ARP, redirects (up to five hops), chunked decoding, status/headers/body dump and a TLS warning.</li>
 			<li><strong>uhttp</strong> — shared ring-3 HTTP/1.1 client used by curl, the browser and chat: URL parsing, redirects (up to eight hops; 1 KB paths and 1.5 KB header lines, enough for OIDC URLs), chunked decoding, timeouts and TLS.  Requests and bodies of any size are split into pieces the transport accepts (1024-byte TLS records, one peer MSS for plain TCP).  Optional per-request fields set the <code>Accept</code> header, extra header lines and a cookie jar; 1xx/204/304 responses are treated as bodyless so keep-alive does not wait for an idle timeout.</li>
 			<li><strong>uhttp_cookie</strong> — the cookie jar (<span class="file">uhttp_cookie.c</span>, 24 cookies of up to 768 bytes).  Every <code>Set-Cookie</code>, including those on redirect responses, is stored; matching cookies are sent on every request and redirect hop.  Cookies are host-only (<code>Domain</code> is ignored), <code>Path</code> is a prefix match, <code>Secure</code> cookies only go over https, and <code>Max-Age&lt;=0</code> or a 1970 <code>Expires</code> deletes a cookie.  The jar outlives the connection, so a cross-origin redirect that reconnects keeps the session.</li>
-			<li><strong>browser</strong> — runs network fetches in up to three headless <code>curl __serve</code> workers, each with its own request/body/meta files under <code>/share/bf&lt;session&gt;_&lt;slot&gt;*</code>.  The session id comes from the browser pid, so multiple browser windows do not share queue files.  Images are prefetched in parallel and decoded as jobs complete, so the UI keeps drawing and scrolling.  Each worker keeps its own TCP/TLS connection; idle helpers stay warm across navigations and exit after ten idle seconds, and losing window focus stops them so raw commands can acquire the NIC.  The status bar reports the page's total, header and first-byte times.</li>
+			<li><strong>browser</strong> — runs network fetches in up to four headless <code>curl __serve</code> workers, each with its own request/body/meta files under <code>/share/bf&lt;session&gt;_&lt;slot&gt;*</code>.  The session id comes from the browser pid, so multiple browser windows do not share queue files.  Stylesheet and external-script bodies are downloaded in parallel but parsed/executed in document order; one image starts before the script phase, and the remaining images are prefetched in parallel and decoded as jobs complete, so the UI keeps drawing and scrolling.  Each worker keeps its own TCP/TLS connection; idle helpers stay warm across navigations and exit after ten idle seconds, and losing window focus stops them so raw commands can acquire the NIC.  The status bar reports the page's total, header and first-byte times.</li>
 			<li><strong>websrv</strong> — the server side, speaking HTTP/1.1 + WebDAV over the TCP listener; see <a href="filesystems.html#webdav">Filesystems → WebDAV</a>.</li>
 		</ul>
 		<p>

+ 2 - 2
docs/userland.html

@@ -373,7 +373,7 @@
 			ngui, the image library, inflate, TLS, uhttp and the vendored MuJS
 			engine. It opens at 1100×700 (960×640 and 780×540 fallbacks on
 			smaller screens), with a URL bar, history, a status bar, inline
-			images and inline/external scripts. Network work runs in up to three
+			images and inline/external scripts. Network work runs in up to four
 			headless <code>curl __serve</code> workers, each with its own files
 			under <code>/share</code>, so the UI keeps drawing and scrolling
 			while several TCP/TLS connections are in flight.
@@ -385,7 +385,7 @@
 			<li><strong>Not supported.</strong> Inline event attributes (<code>onclick=</code>), <code>MouseEvent</code>/<code>CustomEvent</code> and <code>once</code>/<code>passive</code> listener options, <code>type="module"</code>, <code>defer</code>/<code>async</code>, <code>MutationObserver</code>/<code>IntersectionObserver</code>, <code>XMLHttpRequest</code>/<code>fetch</code>, <code>DOMParser</code>, canvas/2D contexts and pseudo-class/element selectors. Basic controls render, focus, edit, toggle, select, submit GET queries and POST <code>application/x-www-form-urlencoded</code> bodies (see the compatibility ladder); <code>getComputedStyle</code> covers the engine's properties, and <code>outerHTML</code> only returns the string last assigned to <code>innerHTML</code>.</li>
 			<li><strong>CSS gaps.</strong> Multiple background layers and <code>background-attachment</code> (a non-uniform <code>background-size</code> uses the width scale), 3D/perspective transforms and transformed text/descendants (scale/rotate paint the box and inline images), pseudo-classes/elements, border-radius clipping of descendants, gradients/box-shadow/transitions and <code>color-mix</code>. Flex rows, card grids, tables with rowspan/colspan, inline SVG and CSS variables are supported.</li>
 			<li><strong>Caps.</strong> 2 MB page body, 832 KB CSS, 6144 DOM nodes, 4608 rules, 16 images. Each image gets an <code>img_estimate()</code>-sized decode arena that is freed after the scaled bitmap is made; navigation calls <code>heap_reset()</code> and unmaps the page heap.</li>
-			<li><strong>Fetching.</strong> Up to three worker processes prefetch images in parallel within the viewport plus 160 px; each worker keeps its own TCP/TLS connection and its own request/body/meta files (keyed by browser pid and worker slot, so multiple windows do not collide).  Completed images are decoded as jobs finish.  Idle helpers stay warm across navigations (they exit after ten idle seconds, and losing window focus stops them), so a second page on the same origin reuses its connection.  Page, CSS and script fetches stay ordered.  The status bar reports the page fetch's header and first-byte times.</li>
+			<li><strong>Fetching.</strong> Up to four worker processes prefetch images in parallel within the viewport plus 160 px; each worker keeps its own TCP/TLS connection and its own request/body/meta files (keyed by browser pid and worker slot, so multiple windows do not collide).  Completed images are decoded as jobs finish.  Stylesheet and external-script bodies are downloaded in parallel but parsed/executed in document order, and one image starts before the script phase so it overlaps script loading.  Idle helpers stay warm across navigations (they exit after ten idle seconds, and losing window focus stops them), so a second page on the same origin reuses its connection.  The status bar reports the page fetch's header and first-byte times.</li>
 			<li><strong>URL entry.</strong> A dotted name without a scheme that is not a known local file extension is treated as a hostname, so <code>cloudron.io</code> does not hit the local-file stat. A typed hostname is tried as <code>https://</code> first, skipping the common <code>http://host</code> → <code>https://host</code> hop; if the https connection is refused, reset, times out or fails the TLS handshake, the browser retries once over <code>http://</code> and replaces the history entry. Origin-level redirects (such as <code>https://host</code> → <code>https://www.host</code>) are cached per process and in <code>/share/borigins</code>; the first visit still follows them, later visits go straight to the canonical origin. Remote stylesheets are cached under <code>/share/bcss-*</code> for the current boot, so a reload or a fresh browser launch skips the CSS downloads.</li>
 			</ul>
 		<p>