惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
The Register - Security
The Register - Security
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The GitHub Blog
The GitHub Blog
博客园 - 司徒正美
罗磊的独立博客
U
Unit 42
S
SegmentFault 最新的问题
Y
Y Combinator Blog
博客园_首页
Hugging Face - Blog
Hugging Face - Blog
J
Java Code Geeks
Schneier on Security
Schneier on Security
Know Your Adversary
Know Your Adversary
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
The Hacker News
The Hacker News
博客园 - 叶小钗
C
Cybersecurity and Infrastructure Security Agency CISA
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Latest news
Latest news
L
Lohrmann on Cybersecurity
A
About on SuperTechFans
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
S
Securelist
A
Arctic Wolf
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threatpost
Scott Helme
Scott Helme
博客园 - 聂微东
博客园 - 【当耐特】
T
Tenable Blog
I
Intezer
D
DataBreaches.Net
B
Blog RSS Feed
Security Latest
Security Latest
C
Cisco Blogs
T
Tor Project blog
N
Netflix TechBlog - Medium

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
How I Built an AI-Powered Adult (Porn) Content Scanner for Windows (And the Engineering Challenges I Didn't Expect)
Mark · 2026-06-12 · via DEV Community

Building an AI-Powered Content Scanner for Windows: Performance, Multithreading and GPU Acceleration in .NET

Building software always looks straightforward from the outside.

You load a machine learning model, point it at some images, and display the results.

At least that's what I thought when I started building DetectNix Vision, a Windows desktop application that performs local AI-powered image analysis without uploading user data to the cloud.

In reality, the project became a deep dive into performance optimization, memory management, multithreading, GPU acceleration, and user experience.

This article covers the engineering challenges I encountered and the architectural decisions I made while building the software from the perspective of a senior developer.


The Original Goal

The initial goal was simple:

  • Scan images stored on a Windows PC
  • Detect potentially explicit or sensitive content
  • Keep all processing local
  • Support both CPU and GPU execution
  • Process large image collections efficiently
  • Remain responsive while scanning

Privacy was a major requirement.

I didn't want users uploading personal files to third-party services. Everything needed to run locally on the user's machine.

That decision immediately influenced every technical choice that followed.


Challenge #1: Model Loading Performance

One of the first mistakes I made was loading the AI model too frequently.

A modern computer vision model can be hundreds of megabytes in size. Loading it repeatedly creates significant startup overhead and quickly destroys performance.

My initial implementation worked perfectly during testing because I was only processing a handful of images.

Once I started testing larger image collections, the bottleneck became obvious.

The Solution

I moved to a singleton-style architecture where the model is loaded once during application startup and remains resident in memory.

private readonly InferenceSession _session;

public VisionEngine()
{
    _session = CreateSession();
}

This reduced initialization costs dramatically and ensured every image could reuse the same loaded model.

The lesson here is simple:

AI models should usually be treated like databases or connection pools, not disposable objects.

Load them once. Reuse them often.


Challenge #2: CPU Usage Was Out of Control

The next issue appeared when processing thousands of images.

The obvious approach is:

foreach(var image in images)
{
    Analyze(image);
}

Unfortunately, this wastes modern hardware.

A single image analysis might only use a fraction of the available CPU resources.

My first instinct was to parallelize everything.

Parallel.ForEach(images, image =>
{
    Analyze(image);
});

This certainly increased throughput.

It also created new problems.


Challenge #3: Too Much Parallelism

Many developers assume that more threads automatically equals more performance.

With machine learning workloads, that's often not true.

I discovered that excessive parallelism caused:

  • Increased memory consumption
  • Context switching overhead
  • Reduced GPU efficiency
  • System responsiveness issues

The application became faster in benchmarks but slower in real-world usage.

The operating system was spending too much time managing threads instead of performing useful work.

The Solution

I implemented a controlled worker model.

Instead of allowing unlimited concurrency, I created a configurable processing pool.

var maxSessions = Math.Min(Environment.ProcessorCount, 4);

This allowed me to tune throughput while keeping resource usage predictable.

In practice, a carefully controlled number of workers consistently outperformed unrestricted parallel execution.

This was one of the most valuable lessons from the project:

The fastest architecture is rarely the one with the most threads.


Challenge #4: GPU Acceleration Isn't Automatic

Many users assume that installing a graphics card means software automatically becomes faster.

Unfortunately, that's not how machine learning inference works.

Supporting GPU acceleration introduced several challenges:

  • Detecting available hardware
  • Selecting execution providers
  • Handling driver differences
  • Supporting systems without compatible GPUs
  • Providing reliable CPU fallback

A failed GPU initialization could not be allowed to crash the application.

The Solution

The startup sequence attempts GPU initialization first.

If that fails, the application transparently falls back to CPU execution.

try
{
    EnableGpuProvider();
}
catch
{
    EnableCpuProvider();
}

This approach ensured the software would run on virtually any Windows machine.

Performance varies significantly between systems, but functionality remains consistent.


Challenge #5: Memory Pressure During Large Scans

Scanning a directory containing 50 images is easy.

Scanning a directory containing 100,000 images is a different problem entirely.

Early versions accumulated too much data in memory.

This resulted in:

  • Increased garbage collection activity
  • Higher memory usage
  • Reduced throughput
  • Longer scan times

The Solution

I switched to a streaming pipeline.

Instead of loading large batches of files, images are processed incrementally.

foreach(var file in Directory.EnumerateFiles(path))
{
    Process(file);
}

This dramatically reduced memory consumption and allowed scans of extremely large collections without exhausting system resources.

Sometimes the simplest optimization is simply processing less data at once.


Challenge #6: Keeping the UI Responsive

Desktop users have very little tolerance for frozen applications.

A scan that takes several minutes is acceptable.

An application that stops responding for several minutes is not.

Initially, image analysis was competing with the user interface thread.

The result was predictable.

Windows marked the application as "Not Responding."

The Solution

I completely separated the scanning pipeline from the UI layer.

The scanner runs on background workers while the UI receives progress updates.

await Task.Run(() =>
{
    StartScan();
});

This allowed users to:

  • Browse results
  • Pause scans
  • View progress
  • Continue interacting with the application

Even during intensive processing.

The difference in perceived quality was enormous.


Challenge #7: Handling Real-World Image Collections

Developers often test with ideal data.

Users never provide ideal data.

Real-world collections contain:

  • Corrupted files
  • Unsupported formats
  • Zero-byte images
  • Huge images
  • Tiny images
  • Invalid metadata

The software needed to continue scanning even when individual files failed.

The Solution

Every image is treated as potentially invalid.

Failures are isolated and logged.

try
{
    Analyze(image);
}
catch(Exception ex)
{
    LogError(ex);
}

A single bad file should never stop an entire scan.

This significantly improved reliability.


Challenge #8: Finding the Right Balance Between Accuracy and Speed

One of the biggest engineering trade-offs involved balancing:

  • Scan speed
  • Detection accuracy
  • Hardware requirements
  • User expectations

Larger models generally improve accuracy.

They also increase:

  • Memory usage
  • Startup times
  • Processing times

Smaller models improve responsiveness but may sacrifice precision.

There is no universally correct answer.

The optimal balance depends on the target audience and intended use case.

For DetectNix Vision, I prioritized a solution that delivered strong accuracy while remaining practical on average consumer hardware.


Additional Engineering Decisions Worth Mentioning

Why I Chose ONNX Runtime

After evaluating several options, I standardized on ONNX Runtime.

Benefits included:

  • Excellent .NET support
  • GPU acceleration support
  • Cross-hardware compatibility
  • Consistent inference performance
  • Easy deployment with Windows applications

Most importantly, it allowed me to focus on building the product instead of maintaining machine learning infrastructure.

Why I Built a Prediction Engine Pool

Creating inference sessions can be expensive.

Rather than constantly creating and disposing resources, I implemented a reusable engine pool.

Benefits included:

  • Reduced allocations
  • Lower startup overhead
  • Better throughput
  • More predictable memory usage

This became particularly important when users scanned tens of thousands of files.

Why Privacy Became a Competitive Advantage

Initially, local processing was simply a technical requirement.

Over time it became one of the product's strongest differentiators.

Many competing solutions upload content to cloud services for analysis.

DetectNix Vision performs all scanning locally.

Benefits include:

  • No image uploads
  • Faster processing
  • Improved privacy
  • No internet dependency
  • Better suitability for business environments

Sometimes architectural decisions become product features.

This was one of those cases.


What I'd Do Differently

Looking back, there are several things I would prototype earlier:

  1. GPU support
  2. Threading architecture
  3. Memory profiling
  4. Large-scale stress testing

Many performance issues don't appear until the software processes thousands of files under real-world conditions.

Building those tests earlier would have saved significant development time.


Key Takeaways

Building AI-powered desktop software taught me that machine learning is only a small part of the problem.

The real challenges often involve traditional software engineering:

  • Resource management
  • Concurrency
  • Reliability
  • User experience
  • Performance optimization

The AI model itself might take months to train.

But creating a fast, stable, user-friendly application around that model can easily take longer.

For me, the most important lesson was this:

Success comes from engineering the entire system, not just the AI.

Users don't care how sophisticated your model is if the application is slow, unstable, or difficult to use.

They care that it works.

And that's where software engineering still matters most.


dotnet #csharp #machinelearning #ai