Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Month: January 2026

C#

Why Exceptions Are Slower Than You Think

- 31.01.26 - ErcanOPAK comment on Why Exceptions Are Slower Than You Think

Exceptions are control-flow bombs. Cost Stack trace capture Heap allocations Cache pollution Rule Exceptions = exceptional cases. Alternative if (!TryParse(value, out result)) { // handle } Cause → Effect Using exceptions as logic → invisible performance debt.

Read More
C#

The Hidden Cost of record Types in Hot Paths

- 31.01.26 - ErcanOPAK comment on The Hidden Cost of record Types in Hot Paths

Records are great.Until you overuse them. Why Value-based equality Copy semantics More allocations in loops Rule Use records for: DTOs Messages Boundaries Avoid in: Hot loops Performance-critical paths

Read More
C#

Why async Code Can Still Block Threads

- 31.01.26 - ErcanOPAK comment on Why async Code Can Still Block Threads

Async ≠ non-blocking by default. The trap await Task.Run(() => LongCpuWork()); You just moved blocking to the thread pool. Rule Async is for I/O, not CPU. Correct Use async APIs for I/OUse background workers for CPU

Read More
SQL

Why COUNT(*) Gets Slow on “Big Enough” Tables

- 31.01.26 - ErcanOPAK comment on Why COUNT(*) Gets Slow on “Big Enough” Tables

It’s not the count.It’s locking + metadata access. Reality COUNT must respect: Isolation level Pending writes Allocation metadata Production alternative Use approximate counts for dashboards. Why Accuracy isn’t always worth blocking.

Read More
SQL

Why Your Index Exists But Is Never Used

- 31.01.26 - ErcanOPAK comment on Why Your Index Exists But Is Never Used

The index is fine.The predicate is not. Example WHERE YEAR(OrderDate) = 2024 Why it fails Functions on columns prevent index seeks. Rewrite WHERE OrderDate >= ‘2024-01-01’ AND OrderDate < ‘2025-01-01’ Cause → Effect Function → scan → CPU spike → slow queries.

Read More
Asp.Net Core

Why IHttpClientFactory Can Still Exhaust Sockets

- 31.01.26 - ErcanOPAK comment on Why IHttpClientFactory Can Still Exhaust Sockets

Most people think it magically fixes everything. Reality Misusing named clients causes: DNS caching issues Handler lifetime misuse Hidden fix Use typed clients for long-lived services. Why Typed clients scope handlers correctly to the service lifetime.

Read More
Asp.Net Core / C#

Why BackgroundServices Die Silently in Production

- 31.01.26 - ErcanOPAK comment on Why BackgroundServices Die Silently in Production

Looks fine locally.Stops running in prod. Root cause Unhandled exceptions inside ExecuteAsync. What actually happens The host kills the service quietly. Correct pattern protected override async Task ExecuteAsync(CancellationToken ct) { while (!ct.IsCancellationRequested) { try { await DoWork(ct); } catch (Exception ex) { logger.LogError(ex, “Background task failed”); await Task.Delay(5000, ct); } } } Cause → Effect […]

Read More
Git

The Hidden Cost of Large Commits (It’s Not Code Review)

- 31.01.26 - ErcanOPAK comment on The Hidden Cost of Large Commits (It’s Not Code Review)

Big commits don’t just slow reviews. Real damage Breaks git bisect Makes rollback risky Hides causal relationships Rule One commit = one reason. Mental model If you can’t describe the commit in one sentence, it’s too big.

Read More
Git

Why git pull Sometimes Corrupts Team History (Even Without Conflicts)

- 31.01.26 - ErcanOPAK comment on Why git pull Sometimes Corrupts Team History (Even Without Conflicts)

The issue is not conflicts.It’s implicit merge commits. What happens git pull = fetch + merge That merge commit: Breaks linear history Hides real change intent Makes bisect harder Safer default git config –global pull.rebase true Why this matters Rebase preserves intent, merge preserves state.Teams need intent.

Read More
Ajax

Why Your Ajax Requests “Randomly” Fail in Production

- 31.01.26 - ErcanOPAK comment on Why Your Ajax Requests “Randomly” Fail in Production

Locally works.Production fails. Cause Preflight CORS requests. What happens Browser sends: OPTIONS /api/data Before: POST /api/data If server doesn’t handle OPTIONS → fail. Minimal fix (ASP.NET example) app.UseCors(builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); Why this matters Ajax failures are often network policy, not JS bugs.

Read More
JavaScript

Why forEach Can Be Slower Than for (And When It Matters)

- 31.01.26 - ErcanOPAK comment on Why forEach Can Be Slower Than for (And When It Matters)

This is NOT about micro-optimizations.It’s about callback overhead. Example items.forEach(item => process(item)); vs for (let i = 0; i < items.length; i++) { process(items[i]); } Why forEach creates a function call per iteration Harder for JS engines to optimize No early break support When it matters Large arrays Hot paths Real-time processing Rule Readability first.But […]

Read More
HTML

The loading=”lazy” Attribute Is Not Just About Images

- 31.01.26 - ErcanOPAK comment on The loading=”lazy” Attribute Is Not Just About Images

Everyone uses it for images.Almost nobody uses it for iframes. Example <iframe src=”https://www.youtube.com/embed/VIDEO_ID” loading=”lazy”> </iframe> Why this matters Prevents layout blocking Improves First Contentful Paint (FCP) Massive win for content-heavy blogs Cause → Effect Less initial network pressure → faster perceived load.

Read More
CSS

Why position: sticky “Randomly” Stops Working

- 31.01.26 - ErcanOPAK comment on Why position: sticky “Randomly” Stops Working

Most people blame the browser.The real reason is parent overflow context. Problem .sidebar { position: sticky; top: 0; } Works… until it doesn’t. Hidden cause If ANY parent has: overflow: hidden; overflow: auto; overflow: scroll; Sticky breaks. Why position: sticky is calculated relative to the nearest scroll container, not the viewport. Fix .parent { overflow: […]

Read More
Windows

Hidden Clipboard Superpower (Nobody Uses This)

- 31.01.26 - ErcanOPAK comment on Hidden Clipboard Superpower (Nobody Uses This)

Press: Win + V You get: Clipboard history Pinned snippets Cross-app reuse Use case Store: SQL snippets Git commands Email templates This alone can save hours per week.

Read More
Windows

Fix Random UI Lag Without Touching Hardware

- 31.01.26 - ErcanOPAK comment on Fix Random UI Lag Without Touching Hardware

Cause Background apps + power profile mismatch. Fix Settings → Power → Power Mode → Best performance Disable “Startup apps” you don’t need Turn off transparency effects Why this works Windows dynamically downclocks UI threads on balanced mode.

Read More
AI

Plan a Real-Life Skill Upgrade in 30 Days

- 31.01.26 - ErcanOPAK comment on Plan a Real-Life Skill Upgrade in 30 Days

Not productivity porn. Real execution. Prompt Create a 30-day plan to learn [SKILL].Constraints: max 45 minutes per day no paid resources weekly measurable outcome final real-world deliverableAvoid motivational language. Be practical. Why it works AI shines at structured planning, not motivation.

Read More
AI

Find Performance Bugs Humans Miss

- 31.01.26 - ErcanOPAK comment on Find Performance Bugs Humans Miss

Humans profile what they expect to be slow.AI finds what’s actually slow. Prompt Review this code for performance risks.Focus on: hidden allocations unnecessary async boundaries repeated I/O GC pressureExplain WHY each issue matters and when it becomes visible in production.Code: [PASTE HERE] Why this matters These issues don’t appear in small test data. They explode […]

Read More
AI

Turn Legacy Code Into Clean Architecture (Without Rewriting)

- 31.01.26 - ErcanOPAK comment on Turn Legacy Code Into Clean Architecture (Without Rewriting)

Use this when You inherit ugly but working code. Prompt Analyze the following code. Identify hidden coupling and responsibility leaks Propose a Clean Architecture refactor without changing behavior Suggest incremental steps, not a full rewrite Show before/after structure diagramsCode: [PASTE HERE] Why it works AI is excellent at structural reasoning, not just code generation.

Read More
Docker

Why Your Docker Image Is Slow Even Though It’s “Small”

- 31.01.26 - ErcanOPAK comment on Why Your Docker Image Is Slow Even Though It’s “Small”

Image size ≠ image performance. Hidden cause Layer invalidation. Most Dockerfiles are written like this: COPY . . RUN npm install Every small file change invalidates the cache. Correct approach COPY package.json package-lock.json ./ RUN npm install COPY . . Cause → Effect Stable dependency layers Faster rebuilds Lower CI/CD costs This is why two […]

Read More
Kubernetes

Why Your Pod “Looks Healthy” But Still Drops Traffic

- 31.01.26 - ErcanOPAK comment on Why Your Pod “Looks Healthy” But Still Drops Traffic

This is a classic production trap. Root cause readinessProbe ≠ livenessProbe Most people use only one. Correct pattern livenessProbe: httpGet: path: /health/live port: 80 readinessProbe: httpGet: path: /health/ready port: 80 Why this matters Liveness = should I restart? Readiness = should I receive traffic? If your app is warming caches or reconnecting DBs, traffic arrives […]

Read More
Wordpress

The Silent SEO Killer: Auto-Generated Attachment Pages

- 31.01.26 - ErcanOPAK comment on The Silent SEO Killer: Auto-Generated Attachment Pages

WordPress creates pages for every uploaded image. What happens Thin content pages Duplicate titles Crawled but useless URLs Fix (no plugin) Redirect attachment pages: add_action(‘template_redirect’, function () { if (is_attachment()) { wp_redirect(home_url(), 301); exit; } }); Why this works You’re reclaiming crawl budget and removing SEO noise. Most blogs never fix this. That’s why it […]

Read More
Wordpress

Stop Using Plugins for Dynamic Content: Use Conditional Blocks Instead

- 31.01.26 - ErcanOPAK comment on Stop Using Plugins for Dynamic Content: Use Conditional Blocks Instead

Most WordPress sites are plugin-heavy for no reason. Hidden power WordPress Block Editor already supports conditional rendering via PHP + block patterns. Example Show a CTA only for logged-out users: if (!is_user_logged_in()) { echo do_blocks(‘<!– wp:buttons –>…<!– /wp:buttons –>’); } Why this matters Fewer plugins → fewer update risks Faster TTFB Full control over UX […]

Read More
Photoshop

Make Cheap Plastic Look Like Premium Metal (Product Photos)

- 31.01.26 - ErcanOPAK comment on Make Cheap Plastic Look Like Premium Metal (Product Photos)

Great for e-commerce & ads. Steps Convert to Smart Object Apply Gradient Map (dark gray → silver) Overlay Directional Motion Blur mask Why it works Metal reflects directionally; plastic diffuses light.You’re faking physics, not color.

Read More
Photoshop

How to Repair a Cracked or Torn Old Photo (Not Retouch — Repair)

- 31.01.26 - ErcanOPAK comment on How to Repair a Cracked or Torn Old Photo (Not Retouch — Repair)

Most people retouch. Professionals reconstruct. Technique Duplicate layer Use Content-Aware Fill only for structure Switch to Clone Stamp (Lighten mode) Why Lighten? It preserves shadows while rebuilding highlights — ideal for cracks. Pro tip Finish with a 5–8% noise layer to unify texture.

Read More
Visual Studio

Why Your Debug Session Lies About Reality (And How to Fix It)

- 31.01.26 - ErcanOPAK comment on Why Your Debug Session Lies About Reality (And How to Fix It)

Ever noticed code behaving differently in Debug vs Release? Root cause Visual Studio injects: Different JIT optimizations Conditional compilation (#if DEBUG) Altered timing (especially async code) Hidden fix Force Release-mode debugging: <PropertyGroup Condition=”‘$(Configuration)’==’Release'”> <DebugType>portable</DebugType> </PropertyGroup> Why this matters Many race conditions only exist in optimized builds.Debug mode can mask real production bugs.

Read More
C#

Why LINQ in Hot Paths Can Kill Performance

- 30.01.26 - ErcanOPAK comment on Why LINQ in Hot Paths Can Kill Performance

LINQ is elegant… and allocates. Problem Deferred execution Hidden enumerators Fix Use LINQ at boundaries, not inside loops. for (int i = 0; i < list.Count; i++) { Process(list[i]); } Why Predictable execution beats elegance under load.

Read More
C#

Why lock(this) Is a Concurrency Time Bomb

- 30.01.26 - ErcanOPAK comment on Why lock(this) Is a Concurrency Time Bomb

You don’t control who else locks this. Fix private readonly object _sync = new(); lock (_sync) { } Why Encapsulation matters in threading.

Read More
C#

Why async void Should Almost Never Exist

- 30.01.26 - ErcanOPAK comment on Why async void Should Almost Never Exist

async void hides exceptions. Only valid Event handlers Wrong async void Process() { throw new Exception(); } Correct async Task Process()  

Read More
SQL

Why Indexes Sometimes Make Queries Slower

- 30.01.26 - ErcanOPAK comment on Why Indexes Sometimes Make Queries Slower

Indexes are not magic. Bad case Low-selectivity columns Over-indexing Diagnosis SET STATISTICS IO ON; Why Wrong index = more lookups than scans.

Read More
SQL

Why SELECT * Destroys Query Performance Over Time

- 30.01.26 - ErcanOPAK comment on Why SELECT * Destroys Query Performance Over Time

Today it’s fine. Tomorrow it’s slow. Why Schema changes Wider rows More IO Fix Select only what you need. SELECT Id, Name FROM Users;  

Read More
Page 1 of 23
1 2 3 4 5 6 … 23 Next »

Posts navigation

Older posts
January 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Dec   Feb »

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (935)
  • How to add default value for Entity Framework migrations for DateTime and Bool (831)
  • Get the First and Last Word from a String or Sentence in SQL (825)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (713)
  • Add Constraint to SQL Table to ensure email contains @ (573)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (552)
  • Average of all values in a column that are not zero in SQL (519)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (474)
  • Find numbers with more than two decimal places in SQL (436)

Recent Posts

  • C#: Use ArgumentNullException.ThrowIfNull for Cleaner Validation
  • C#: Use Discard Pattern to Ignore Unwanted Values
  • C#: Use Deconstruction with Tuples for Cleaner Multiple Returns
  • C#: Use File-Scoped Types to Limit Class Visibility
  • SQL: Use PIVOT to Transform Rows into Columns
  • SQL: Use MERGE OUTPUT to Track What Changed During Upsert
  • .NET Core: Use Polly for Resilient HTTP Requests with Retry Logic
  • .NET Core: Use Dapper for Lightweight ORM Alternative to Entity Framework
  • Git: Use git sparse-checkout to Clone Only Specific Folders
  • Git: Use git switch and git restore Instead of Confusing git checkout

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (935)
  • How to add default value for Entity Framework migrations for DateTime and Bool (831)
  • Get the First and Last Word from a String or Sentence in SQL (825)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (713)

Recent Posts

  • C#: Use ArgumentNullException.ThrowIfNull for Cleaner Validation
  • C#: Use Discard Pattern to Ignore Unwanted Values
  • C#: Use Deconstruction with Tuples for Cleaner Multiple Returns
  • C#: Use File-Scoped Types to Limit Class Visibility
  • SQL: Use PIVOT to Transform Rows into Columns

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com