Skip to content

Commit 9bf4eca

Browse files
committed
Larger chunkrs in tailwind and biome downloads
1 parent 42f2eed commit 9bf4eca

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

plain-code/plain/code/biome.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ def download(self, version: str = "") -> str:
121121
label="Downloading Biome",
122122
width=0,
123123
) as bar:
124-
for chunk in resp.iter_content(chunk_size=8192):
124+
for chunk in resp.iter_content(chunk_size=1024 * 1024):
125125
f.write(chunk)
126126
bar.update(len(chunk))
127127
else:
128-
for chunk in resp.iter_content(chunk_size=8192):
128+
for chunk in resp.iter_content(chunk_size=1024 * 1024):
129129
f.write(chunk)
130130
os.chmod(self.standalone_path, 0o755)
131131

plain-tailwind/plain/tailwind/core.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,40 @@ def download(self, version="") -> str:
125125
else:
126126
url = f"https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-{self.detect_platform_slug()}"
127127

128-
with requests.get(url, stream=True) as response:
128+
# Optimized requests session with better connection pooling and headers
129+
session = requests.Session()
130+
131+
# Better connection pooling
132+
adapter = requests.adapters.HTTPAdapter(
133+
pool_connections=1, pool_maxsize=10, max_retries=3, pool_block=True
134+
)
135+
session.mount("https://", adapter)
136+
session.mount("http://", adapter)
137+
138+
# Optimized headers for better performance
139+
headers = {
140+
"Accept-Encoding": "gzip, deflate, br",
141+
"Connection": "keep-alive",
142+
"User-Agent": "plain-tailwind/1.0",
143+
}
144+
145+
with session.get(url, stream=True, headers=headers, timeout=300) as response:
129146
response.raise_for_status()
130147
total = int(response.headers.get("Content-Length", 0))
148+
131149
with open(self.standalone_path, "wb") as f:
132-
if total:
133-
with click.progressbar(
134-
length=total,
135-
label="Downloading Tailwind",
136-
width=0,
137-
) as bar:
138-
for chunk in response.iter_content(chunk_size=8192):
150+
with click.progressbar(
151+
length=total,
152+
label="Downloading Tailwind",
153+
width=0,
154+
) as bar:
155+
# Use 8MB chunks for maximum performance
156+
for chunk in response.iter_content(
157+
chunk_size=1024 * 1024, decode_unicode=False
158+
):
159+
if chunk:
139160
f.write(chunk)
140161
bar.update(len(chunk))
141-
else:
142-
for chunk in response.iter_content(chunk_size=8192):
143-
f.write(chunk)
144162

145163
os.chmod(self.standalone_path, 0o755)
146164

0 commit comments

Comments
 (0)