The Windows Clock: Why Seconds took Years

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
there's big news in Windows land the system clock will finally be getting a second display in the system tray the feature that has been curiously absent for almost 30 years now clearly Windows has always known the time down to the latest microsecond but it's always refused to display seconds and believe it or not there are a number of very good reasons why it's been hidden from you all these years find out what those reasons are and why they did it that way right now in Dave's Garage [Music] thank you hey I'm Dave welcome to my shop I'm Dave Plummer a retired operating systems engineer from Microsoft going back to the MS-DOS and Windows 95 days and today we're going to look at the reasons why it's taken almost 30 years to get an option to turn on the number of seconds on the Windows clock the clock down in the corner is part of the tray which is part of the Explorer process which is part of the windows shell which my team at Microsoft owned for more than a decade put more simply I've touched the code and I can appreciate the reasons behind their original decisions and today I'm going to explain them to you in a way that should give you greater insight into how Windows works and some of the challenges faced by operating systems Developers keep in mind that this is just of course my personal recollection and speculation and not official in any way I'm long since retired but when I was working on the Windows tray in about 95 the first thing I noticed was something interesting about the windows clock at least it was designed to work back then the first thing was that it did not and could not display seconds in fact the code never looked at the number of seconds even when painting there must be a reason but what well spoiler alert it's all about system performance now I know what you're thinking it probably takes like a millisecond at best to draw a clock and no more than that so how can it be about perf well your system performance generally comes down to a few important metrics CPU memory and disk each of those including the disk part can have a role in your system speed and constitutes a reason why Windows does not draw seconds for the clock let's start with the easiest of those CPU usage now it goes without saying that if your clock is going to display seconds it needs to be able to do so at least once a second so once per second is the minimum number of times the clock will need to paint itself in an operating system like Windows getting the time of day formatted in a useful format is not exactly trivial behind the scenes there are many factors that influence how the clock will be formatted such as whether you're running in 12 hour or 24 hour time mode what your clock's separator character is and so on all of these options are stored in what's known as your system Locale and they will have defaults appropriate to your region that can then be changed as needed the points however is that there's a non-trivial amount of calculation needed to be done in order to display the clock properly and those calculations will take some amount of time now grant that even on a slow machine we're still likely talking milliseconds at best let's say it takes 10 milliseconds to look up the needed info and to paint the clock that means it happens once per second or once for every 1000 milliseconds so that out of those 1000 milliseconds a mere 10 are used by the clock the question at that point becomes whether or not displaying the clock is worth 0.1 percent of your CPU it does mean that every Benchmark every test is going to produce a fractionally lower result and remember people were coming to the new windows user interface from having used win31 which doesn't even show the current time at all everything about the new versions of Windows would be compared back to and tested against the prior versions and any slowdown would be unacceptable even if 0.1 percent of your CPU were an acceptable loss keep in mind that this is likely only one of a dozen or more similar decisions that had to be made and if the philosophy of keeping those things fast had not been adopted quite universally way back then then the odds are that the performance impacts of each of them would have been additive those 10 milliseconds are just the camel's nose in the tent and after that everyone is going to expect that their pet feature will be fine as long as they don't take more time than let's say the clock needs you might be saying but once a second it has to check the time to see if it has to paint a new minute value anyway so the savings really can't amount to much but Windows doesn't need to check the time every second to see if the minute needs to roll over what it does instead is to calculate the amount of time from now until the clock will roll over the minute let's say the current time is 10 20 in 40 seconds all it needs to do is recognize that the time will be changing 20 seconds from now and to display accurate results in the tray is to then set an internal wake-up timer it can go completely to sleep at that point doing nothing whatsoever and requiring no service from the system until those 20 seconds have elapsed at that point the system will wake up the clock code and ask it to draw the new time and let it go back to sleep for another 60 seconds as long as we don't have to contend with the seconds this code can remain quiescent for most of its existence and that's the win still some of you might be of the belief that a fraction of a percent of your CPU is a fine thing to trade for such niceties and that's fine it's certainly even way more true today where you can have dozens of cores pushing more than five gigahertz and you can certainly likely spare the Cycles to draw the clock even when benchmarking even so it can still matter and that's because the real impacts of allowing the clock to draw seconds will be mostly manifested on low memory systems keep in mind that a Windows 95 PC only had to have four megabytes of RAM and that's just what the box spec listed as the minimum system configuration let's not make the mistake of thinking that a four megabyte Windows 95 machine was fast but it worked and it ran and the development team had to do everything in its power to keep it that way the problem was that Windows was so memory constrained on a four megabyte minimal system that doing practically anything meant you needed virtual memory to do it and to talk about why even a clock could be so expensive then we need to talk a bit about virtual memory to understand how it works imagine for a moment that you are the operating system under Wind 32 each process has access to about two gigabytes of memory address space no matter how much actual physical RAM you have installed and so the RAM installed is usually only a fraction of that size when there are only four megabytes of actual Ram How Could You effectively manage it if altogether the system and applications needed the use of six megabytes would you just give out the four Megs that asked in order and then fail the request for the last two Megs well that'd be no fun and fortunately that's not what Windows does what Windows does do is to give out all of six megabytes of memory broken up into 4K Pages or blocks as memory requests come in then it satisfies them by handing out blocks of address space that look like they're going to be Ram but aren't actually backed by any Ram at all it's only when the program actually tries to use that memory by touching it that the CPU will magically jump in at the last second and put a real page of ram where the program is looking it's almost like a magic trick imagine that the ram is represented by ping pong balls and that memory allocations look like upside down Solo cups in a perfect world with apple free memory the system can simply assign Ram to every upside down cup but what if you have six megabytes of memory requested and only four megabytes installed to fulfill those requests in that case you have only four ping-pong balls and six cups yet every time you look under a cup there's a ball there that's because the operating system cheats a little when you're not looking it can move a ball from another cup to the one you're about to Peak under as far as the programs can tell there's Ram under each cup but it's the operating system that's moving things around to create that useful illusion if that little analogy makes any sense at all then it's time to look at how virtual memory really works under the covers in essence it's a memory management technique used by windows and many other modern operating systems that abstracts the memory address space available to a process from the physical memory installed on the machine it allows each process to operate as if it has exclusive access to the main memory even when sharing it with other processes first the memory is broken up into blocks the memory address space both physical and virtual is divided into these fixed size blocks known as pages the size of a page can vary depending on the system but it's commonly four kilobytes in our example A Memory page was represented by the Solo cups those cups will all live within the cpu's address space on a 32-bit system after the kernel reserves its own large block of address space we're left with two gigabytes of address space for the user process in 1995 that was a huge amount but as the decades rolled by and software grew in size and power we've moved on to 64 bits by now still the virtual memory procedure stays the same each process in Windows has its own private virtual address space which is divided into two regions user mode and kernel mode the user mode region is unique for each process while the kernel mode region is shared amongst all processes to keep track of which pages of virtual memory correspond to which pages of physical memory Windows NT uses a data structure called the page table each process has its own page table it is the page table that keeps track of all the Solo cups when a process needs to access a page of memory it refers to its own virtual memory address the system looks up the address in the page table to find the corresponding physical memory page if the page is not in physical memory a condition known as a page Vault where there's no ball under the cup it is fetched from the disk and loaded into RAM this step is how and where the system magically inserts a ping pong ball before you can even look under the cup and as a side this is done with the mmu or memory management unit of the CPU at this point I hope something is bothering you perhaps about this whole system and that's the fact that if I let one process use a page of ram I can't just steal that RAM and give it to another process to use Not only would it already be full of perhaps secret results created by the first program but anything that you wrote as a second program would screw up the first clearly two programs can't share the same Ram block right well that's mostly true what Windows does is that when physical memory is running low the operating system can free up some space by moving or swapping some pages from physical memory back onto the disk into a special file known as the page file or the swap file these Pages can be either selected from idle Pages or pages that haven't been accessed in quite a while the system does its best to pick a page that likely won't have to be continually moved around every turn but when a guess is wrong or when there's just way too little physical RAM for the demands your old mechanical hard drive would grind away as a system paged as hard as it could the lights were always on and yet it was like nobody was home the use of virtual memory provides several real benefits it allows processes to run in their own dedicated memory space thus preventing them from writing into the memory spaces of other processes which increases system stability quite a bit if I process a in your process B and I write through address 10 000 in my memory I can't even see your memory let alone corrupt it you have your own address ten thousand it will point to a completely different real page virtual memory enables systems to run more applications than would be possible with only physical memory as Idle or infrequently used Pages can as we noted be swapped onto the disk it also simplifies programming by allowing programmers to act as though there is a large amount of memory available to their applications even if the physical memory is limited now that you have at least a general understanding of how virtual memory works and the steps that the system has to undertake in order to swap these Pages between RAM and disk you can perhaps appreciate why even disk speeds will affect performance once virtual memory is being used it's because those pages have to be read from and written to disk when they are moved and this makes the performance of the CPU in turn dependent on the performance of the disk if your system is memory constrained to the point that you have no free Ram left and the system has to page some it will be very slow but how does this impact something small like the clock well if the clock were merely painting itself it might not be too bad but for the clock to be able to paint itself it has to read the current time it then has to format the time in the correct order with the correct separators in the correct 12 or 24 hour time format and all of that code from the timekeeping code to the localization settings has to be paged into memory from disk once every second and then paged back out on demand that means it could hit the disk twice for every page as small as 4K as the code executes the four megabyte system that Windows 95 targeted was memory constrained at most times and that meant that any additional real work would need virtual memory everything the clock touches or references must be paged into physical RAM and that's an incredible speed penalty worse it's not a one-time issue like something in the boot path that slows down your startup it runs every second and so from the user's perspective that's pretty much continuous meaning the clock code will effectively be allocated at 64k of Ram or whatever it is for the life of the system after all just how useful is the ram being shared if you can only use it for less than a second once every second if the clock only updates once per minute though then the code required is flashed in and out only once per minute and the memory will remain available for paging the entire minute in between faced with those choices if you were Microsoft your choice is at that point are either not to offer seconds at all or to bump the memory required for the system by some amount with four mags being a hard limit for some systems of the day bumping it to six Megs could have cut off too large a piece of the market and so faced with a hard choice they fail to offer seconds for the benefit of increasing available memory and reducing swap file usage it's a decision that I think made a lot of sense in 1995. but talking about a few dozen kilobytes here and there seems silly when you consider that my desktop machine has 128 gigabytes of memory that's more than 131 000 megabytes so we have more than Apple space for a second's display today and that perhaps is amongst the reasons why Microsoft has finally decided to relent and include a second display on the Windows clock it's actually come and gone in the past and for reasons I'm not privy to and it became a registry only option for Windows 10. in the latest release of Windows 11 however you can turn it on by going to settings and then personalization taskbar and then taskbar behaviors under there you will find a new option to show seconds on a system clock finally after Decades of being denied you can turn on your clock and put the immense processing power of your multi-core CPU and gigabytes of RAM to some good use if you found today's episode to be any combination of informative or entertaining remember I'm mostly in this for the subs and likes so please leave me one of each before you go today and make sure you turn on the Bell notification icon so that you get notified of my somewhat sporadic release schedule I'll be bringing you a ton of Insider stories that you won't want to miss in the meantime and in between time I hope to see you next time right here in Dave's Garage
Info
Channel: Dave's Garage
Views: 182,214
Rating: undefined out of 5
Keywords: windows, clock, seconds, history, task manager, windows clock widget, windows clock on desktop, windows clock app, windows clock screensaver
Id: qe1ltXdKMow
Channel Id: undefined
Length: 15min 4sec (904 seconds)
Published: Wed Jul 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.