introducing winapi: comparing gc pressure and performance with winforms

GitHub: WinApi

tl;dr - performance stats

Direct message loop performance: 20-35% faster.
Heap allocation: 0MB vs. roughly, 0.75GB / 100k messages.
Memory page faults (Soft): 0.005% - A mere 5k vs. roughly 1 million faults/100k messages)

WinApi's primary objective is to provide access to the native layers of the Windows API from the CLR. However, even on first look it should be clear that the WinApi.Windows namespace infringes on the WinForms territory, even though its a tiny sub-fraction of the size of WinForms. Over the years WinForms has been well optimized to be decent - It's not the most efficient beast, but for common programs, it probably takes up less than 2-5% percent of your application's time that it doesn't matter on modern hardware - or so is the general line of thought. However, what's one can refute is that it never was the same as say, ATL/WTL in C++ or direct Win32 programming to be able to handle message loop heavy applications, or high-performance games.

The WinApi.Windows advantage

  • The assembly code generated by the JIT is directly comparable to ATL/WTL or a Win32 application written by hand.
  • The message loop is completely GC-allocation free.
  • You have complete control over how messages are processed. You can entirely short-circuit, or manually extend connection points into the message loop logic. ...

introducing winapi: graphics with direct3d, d2d1, gdi, opengl and skia

GitHub: WinApi

As I introduced the basics of WinApi in my previous articles, it may make sense to actually present something on the screen. And how better to do it, than by using the lowest-level of software drawing layers.

[Image]

Actually, the title probably includes every major drawing library other than Cairo, but I choose Skia for the purposes of demonstration here, since its at the crux of both Google Chrome and Firefox. It may seem overwhelming that I'm demoing all of these technologies in a single article, but this is where the helpers of WinApi gives a hand to make all this super easy, without compromising on the performance.

The GDI Window

Let's start with the most fund ...

introducing winapi: basics

TagsWinApi | DotNet | C#

GitHub: WinApi

In the previous article here, I discussed the evolution of programs that use the Windows API with C/C++ and C# snippets, and it ultimately ended out with this C# snippet:

static int Main(string[] args)
{
    using (var win = Window.Create(text: "Hello"))
    {
        win.Show();
        return new EventLoop().Run(win);
    }
}

Yup. That's fully functional code that works. Just add references to WinApi, and WinApi.Controls which are both less than 150kb combined, and it'll do what its excepted to do. However, before I get into samples that look nifty, let's look at a precise translation of the C/C++ program in the previous article, without the use of the Window abstraction that WinApi provides in the helper namespace WinApi.Windows.

A very raw program that uses the Windows API would look like this: ...

introducing winapi: the evolution

TagsWinApi | DotNet | C#

GitHub: WinApi

The Windows API is over two decades old - yet one of the most used APIs that has stood the test of time. In today's short lived software world, you don't see a lot of user mode public APIs that stay the same for even a short time. But even a program that was written 20 years ago (assuming only the official and documented APIs by Microsoft were used) will run spot-on as intended, with almost no changes - That's quite cool if you think about it. You can't say that even about some of the oldest user mode UNIX APIs. It's a testimony to the well-design architecture and the amount of work Microsoft put into compatibility while modernizing everything both underneath, and above it, while keeping the core user mode APIs exactly the same.

the good old c-lang way

A Hello World of Windows, in C today, would resemble something like this below. ...

windows insider - profile

I've been a Microsoft Insider ever since its inception, and I have a habit of sending detailed bug reports and patches if I have the time to pretty much most of the open source software I tend to use for over a few hours. Keeping with that habit, there's quite a lot feedback that I had submitted early on (At the time of writing this, I probably have around a hundred feedbacks already). And not long ago, the Insider Hub app got a bunch of Achievements (a potential attempt at a basic gamification to encourage participation). And well, seems like as of a few days ago, I've gotten all of the so-called "Achievements". Ha! - I did think it was rather childish of me to write about this. However, it's simple, easy and helps shape the platform. Perhaps it may add a little more motivation for someone.

[Screenshot]

I generally tend to live on the bleeding-edge. Most of my systems a ...

crash analysis: windows bsod - netwbw02.sys

This issue has been filed with Microsoft, and the current state of the issue can be followed up on Microsoft TechNet if you're affected by it or would like to add on to it here: Windows 10: Netwbw02.sys crash on all Threshold and Redstone builds (so far)

Affected Configuration

  • Windows 10 - OS Build 10586+
  • Intel Dual-Band Wireless AC 3160

Error Codes

  • DRIVER_IRQL_NOT_LESS_OR_EQUAL
  • 0xdead039e
  • 0xdead7495

The Context

Initally, I had few BSOD with the Netwb02.sys (Intel's WiFi driver) during the Windows Insider builds, with DRIVER_IRQL_NOT_LESS_OR_EQUAL. That's a straight forward issue with the self-explanatory problem code - the driver is accessing improper memory addresses which ended up in higher IRQL. Obviously, Intel's Wi ...

crash analysis: windows graphics stack bug

This issue has been filed with Microsoft, and the current state of the issue can be followed up on Microsoft TechNet if you're affected by it or would like to add on to it here: Graphics stack bug - Windows 10 Build Threshold Release (10586+, including RedStone)

Affected Configuration

  • Windows 10 - Threshold Release (10586+, including the initial builds of RedStone)
  • Intel HD Graphics 5500 with Nvidia GeForce 950M (Optimus pipeline)

The Context

A few weeks ago, being on the Insider Fast Ring, I updated myself to the first release based on the Redstone build likely during the first few hours. Some of the issues I noticed ended up being documented a few days later. My laptop was a HP Envy 15 with an Nvidia Optimus based GeForce 950M, ...

the old new thing - reincarnation of my blog

TagsTech | Web | React

GitHub: prasannavl.com

My blog was never really alive. A few posts years ago, and that was about it. Off late, I've been working with web technologies again after a long time. The last I had worked with JavaScript - V8 was in its infancy, and JavaScript outside of V8 wasn't exactly a great language, especially for someone like myself who lived in the dual ecosystem of C/C++, and .NET. But today a lot has changed, and even the sheer number of web technologies can be over-whelming. So, I decided build myself a website with the cutting edge web pieces of today. Technically, its really a single web application, complemented by server-side static site generation to provide all the goodness of a more traditional website.

Today's Web

The JavaScript ecosystem is now extremely powerful, sitting comfortably just a little below the likes of .NET and Java ecosystem - you can use high performance buffers, ...

javascript locks

Note: This article is here only for historical reasons. Do not ever do this, unless you know what you're doing. Also note that this is more of a task library than just for locking - this was a way to solve a particular problem I was facing. That being said, this is almost always a wrong approach for any problem in today's javascript ecosystem. :)

Things break. Codes break. Javascript - they don't just break, they break everything along with it. Being the simplest language has its downsides. But one of the common reasons that happen is people tend to forget that everything in JS is asynchronous.

You probably would get away with it, if you're writing simple applications. But when complexity increases, it almost becomes impossible to solve certain problems with the async design pattern, not without a locking mechanism. Especially, in a javascript environment due to its full async nature making timing absolutely un ...

mongodb session state provider for asp.net

GitHub: MongoSessionProvider Nuget

I've been pretty impressed with the recent development of MongoDB, and it seems to me that their one biggest problem of data consistency has now been solved.

And so, I decided to give it base one of our upcoming projects fully on MongoDB. But after some Googling I found out all the session providers out there are pretty outdated using deprecated libraries, or not suited for high-performance needs.

So, here's a session provider for ASP.NET.

Installation

PM> Install-Package PVL.MongoSessionProvider

Example session document ...

pvl-stockplus - custom rom for motorola defy plus

wow i never seen a smoother and a faster rom, is very responsive and i love status bar, animations and roboto!! thanks for this awesome rom!!” - FraRiva91 (XDA)

Thanks! Rom is very fast and smooth.” - korto (XDA)

So, after staying at CM for a long time, I came across the recent release of Motorola's ROM. And I must admit, for the first time, I was quite impressed. It was snappy, fast and stable. So, I guess I came to a point where I wanted everything to just work instead of hovering around nightlies, making this stock version a perfect base to rectify Motorola's shortcomings, like the God-awful transitions, the complex and ugly loading icon, and well, root, busybox, memory optimizations and all the other performance goodies. I'm a fan of keeping things simple and elegant, rather than complicating things unnecessarily. And I thought, I would share it this time, for those who prefer ...

motorola defy - upgrade/downgrade kernels

XDA Thread

Motorola has a strange way of controlling their phone. They release an update which prevents us from upgrading to newer kernels released for the same phone in different geographic regions. So, after almost bricking my phone, I finally was able to find a way to downgrade my kernel, so that I can upgrade to an even newer version again.

So, here's my post regarding the same on XDA:

People who are stuck with 4.5.1-134_DFP-13XX Kernels and or any BL6 SBFs on the Motorola Defy(+) may now freely switch between any kernels they require, using the below SBF.

Say for example, to upgrade to Walter's fixed SBF of 4.5.3_109 Kernel from 4.5.1-134_DFP-13XX, do the following.

  1. Flash Defy-BL6Downgrade-CDT.sbf through RSD Lite.
  2. Flash walter's 4.5.3_109 kernel sbf right away after that or an update zip package if you have a functional recovery. (Actually, you may flash any kernel. ...

automate your tv show downloads

So, TV shows. I found myself checking websites for new episodes often, and if available, download and add it to my download list. The same exact process. Should write a short program to do that, I thought. But never happened.

And it all changed recently, as I had sat down for food waiting for my order. I had just discovered Scripting for Android a while back - I was able to write and run Python code off my phone. Pretty cool. And I happened to overhear a conversation about the latest episode of House. Hmm.

And so I started typing out a script to check for TV shows. By the time lunch arrived, I had already written the part to search my phone for existing shows and retrieve the full list of shows from the internet. Pretty smooth. I was already quite excited about running python beautifully on Android.

And well, despite my temptations to code on my phone, touch is just not productive enough for coding. Not yet. And there, got back to my room and finished it. ...