SShortSingh.
Back to feed

Why Result::map_err Can Slow Down Your Rust App

0
·3 views

Rust developers often use map_err to convert errors into a unified type, but it has a hidden performance cost. The closure passed to map_err runs eagerly, so any logic inside it executes even when the Result is Ok. In hot code paths, these unnecessary conversions can accumulate into measurable overhead. A common remedy is to keep heavy logic out of the closure or to use anyhow::Context instead. Context defers error construction and string formatting until the Result is confirmed to be an Err.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Google's site: search returns empty results for pages it has indexed

Since around 19 November 2026, searching Google with site: plus a page's full address often returns nothing, even for pages that are indexed. Before that change, the same search usually displayed the page. A developer running a bulk index checker found that about three in ten of 85 pages marked as not indexed were actually present when re-checked on 21 November. Results that do show a page remain reliable, but an empty site: response no longer proves a page is missing. The author suggests searching the bare URL without the operator and repeating the query before concluding a page is not indexed. Google has not explained the change, and it is unclear whether it is limited to certain markets.

0
ProgrammingDEV Community ·

AWS IMDSv2 Architecture Explained: How Session Tokens Help Block SSRF Attacks

The Amazon EC2 Instance Metadata Service gives running instances details about their environment, including temporary IAM credentials, which makes it a sensitive internal target. Server-Side Request Forgery flaws can let attackers reach this endpoint from inside an application. AWS introduced IMDSv2 to make such attacks harder by requiring a session token obtained through a PUT request before metadata can be read. The token has a configurable lifetime of one second to six hours and is sent in a header with subsequent requests. The article also covers enforcing IMDSv2 at scale using AWS CLI, Terraform, and Service Control Policies.

0
ProgrammingDEV Community ·

Complex branching in pull requests linked to 29% higher agent review token costs

A developer found that their monthly AI agent review bill for a Node service rose about 18% while pull request volume stayed roughly flat. Referencing a study of 465 open source pull requests that tied low code health to 22-35% higher inference costs, they examined 36 merged pull requests from their own service. Using a crude proxy counting branching constructs in added lines, they compared the most branch-dense third of changes against the least. The densest third consumed about 29% more input tokens per changed line, a result within the range the larger study reported. The author cautions that this small single-service sample is not a rigorous confirmation of the effect.

0
ProgrammingDEV Community ·

Fine-Tuning LLMs Is Not Debunked, but It Suits Behavior Changes More Than New Facts

A vendor-authored piece argues that fine-tuning an LLM remains valid, citing research that finds it poor for teaching new facts but effective for shaping behavior on narrow tasks. It notes that retrieval-augmented generation outperformed fine-tuning on knowledge tasks in one study, and that many-shot prompting can rival fine-tuning on some tasks. Cited work includes Meta's LIMA, which reached strong quality from 1,000 curated examples, and the LoRA Land report on 310 fine-tuned models. The author also flags that fine-tuning can erode prior capabilities, with full fine-tuning learning more but LoRA better preserving out-of-domain performance. The article frames the choice as depending on whether the gap is knowledge or behavior and whether results can be measured.