SShortSingh.
Back to feed

How Replacing Nested Loops with Hash Sets Cut a Batch Job from 4 Minutes to 200ms

0
·1 views

A software developer discovered that a duplicate-checking function using two nested loops, which runs in O(n²) time, caused a nightly batch job to freeze for several minutes when processing a million-record dataset. The root cause was that the quadratic approach required roughly five billion comparisons for large inputs, consuming 90% of CPU and triggering server alerts. Replacing the nested loops with a hash-based Set reduced the algorithm to O(n) linear time, since each insertion and membership check on a Set is amortized constant-time. The optimized function completed the same batch job in under 200 milliseconds, compared to the previous four-minute runtime. The case illustrates why understanding Big-O notation allows developers to reason about performance before writing code, rather than discovering bottlenecks only under production load.

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 ·

Mistral Releases Shieldstral 1.0, a Self-Hostable 3B Moderation Model Under Apache 2.0

Mistral launched Shieldstral 1.0 on August 5, 2026, a 3-billion-parameter model built specifically to moderate text and image content before it reaches end users. The model runs on a single 16GB GPU in BF16 precision and is available on Hugging Face under an Apache 2.0 license, making it accessible to self-hosters without third-party API dependency. A key feature is its policy-adaptive design, allowing moderation rules to be defined in natural language within the prompt rather than requiring retraining when community guidelines change. Mistral reports strong benchmark performance, including 99.4% F1 on HarmBench and 97.7% on the multimodal VLGuard set, though these figures are vendor-reported and have not yet been independently verified. The model supports popular inference frameworks including vLLM, llama.cpp, and SGLang, and is intended as a specialized moderation layer alongside other models rather than a general-purpose replacement.

0
ProgrammingDEV Community ·

Isolation Forest vs GPT-4o: Choosing the Right AI Log Anomaly Detection Tool

Engineering teams moving beyond static threshold alerts for log anomaly detection face a key choice between statistical ML models like Isolation Forest and LLM-based tools like GPT-4o. Statistical models such as Isolation Forest and Prophet are fast, cost-effective, fully on-premise, and produce explainable results, but require manual feature engineering and regular retraining to stay accurate. LLM-based approaches like GPT-4o require no feature engineering and can interpret semantic context in logs, but raise serious data privacy concerns when logs contain API keys, PII, or session tokens. The practical decision hinges on three factors: daily log volume, whether real-time alerting or post-incident triage is needed, and whether sensitive data can legally be sent to a third-party API. Choosing the wrong approach for your constraints — especially around compliance — can create significant remediation challenges after the fact.

0
ProgrammingDEV Community ·

15 Hours Lost: How Poor Docs and No Setup Scripts Hurt Junior Mobile Devs

A developer onboarded two junior engineers onto a React Native Expo project last week and logged every friction point they encountered. Both developers had web React experience but no mobile background, and each lost roughly 15 hours to avoidable setup and documentation failures. Common blockers included Node version mismatches, missing Xcode tools, misconfigured Android SDK paths, and confusion between Expo Go, dev builds, and EAS builds — none of which were addressed in the README. Undocumented auth patterns caused one developer to rebuild a token-refresh mechanism that was already running silently in middleware. The author concludes that a single setup script and a few focused documentation pages could have prevented nearly all of the lost time.

0
ProgrammingDEV Community ·

VIDRAFT Releases AX-RAY AI Safety Benchmark and Open Leaderboard on Hugging Face

AI safety firm VIDRAFT has publicly launched AX-RAY, a diagnostic framework built around 117 evaluation items designed to identify latent risk behaviors in large language models and AI agents. The framework's central focus is detecting 'Causal Leakage,' a failure mode where a model's outputs are influenced by hidden or unintended causal cues rather than transparent reasoning. Two publicly available general-purpose AI models, including one from NVIDIA, showed anomalous signals on this dimension during evaluation. AX-RAY also features jurisdiction-aware assessments that map safety risks to national laws and cultural normative systems, with intended applications spanning finance, healthcare, robotics, and public services. The evaluation dataset is freely accessible on Hugging Face, and VIDRAFT clarifies that an anomalous signal indicates a potential vulnerability requiring further investigation, not confirmed harmful behavior.

How Replacing Nested Loops with Hash Sets Cut a Batch Job from 4 Minutes to 200ms · ShortSingh