Giter Site home page Giter Site logo

mhtvssfrphde / prefetch Goto Github PK

View Code? Open in Web Editor NEW
48.0 6.0 3.0 613 KB

Load file into ram for fast first access.

License: MIT License

C++ 81.54% Python 8.95% Batchfile 1.18% QMake 6.13% C 1.88% PowerShell 0.32%
superfetch disk-cache system-optimization memory-management cache hifi prefetch

prefetch's Introduction

prefetch

Download

https://github.com/mhtvsSFrpHdE/prefetch/releases

Linux version may not up to date during active development.
Most recent Linux version: https://github.com/mhtvsSFrpHdE/prefetch/releases/tag/4.5

How to use

Frequently asked questions

https://github.com/mhtvsSFrpHdE/prefetch/wiki/FAQ_01_Frequently-asked-questions

What is this

Load program file to RAM before use, so they may perform faster.
Designed to speed up browser like Firefox at the beginning.
Other HDD heavy program may benefit from it like 3DS Max.

According to this research, by move data from hard drive to RAM,
this may save you from a $700 Hifi SSD.
Because move data to RAM before use will physically erase any difference between different type of hard drives.

System requirement

  • 16 GB System RAM, or at least to prepare 4 GB "Available RAM" can reserve for cache.

"Available" is the one in Windows Task Manager Memory tab.

Background

In most cases, the Windows prefetch mechanism will not function as you wish.
Indeed, it has many smart tricks than other ancient Windows version,
but it was still not configurable, your common software result in running slow,
even on some modern large memory hardware, e.g. greater than 16 GB.

Let's say when you have 32 GB system memory,
there's a lot of empty space to hold your entire software files and user data.
But Windows won't do that, so when you are trying to open the software,
Windows always read them from disk instead of memory.
That's how you won't benefit from this "prefetch" mechanism.

The prefetch project created for this situation:
It maintains an "include" and "exclude" folder list.
Each time a preset interval triggered, it will read your software and user data into memory,
then discard them to null. Windows will notice the reading behavior and cache those data in memory,
So the next time you truly run the software, you will read the software files from memory directly.

A roughly test shows Firefox with a lot of extension:

  • Boot the PC, wait the disk stops reading, that shows Windows completed the prefetch.
  • Open Firefox, it takes 26 seconds to load all files and ready to use.
  • Reboot and wait for Windows to prefetch again, but set this "prefetch" project to run at startup.
  • Open Firefox, it takes 3 seconds to load.

This is FAST a lot.
The other reason to use prefetch is,
Windows prefetch is dynamic. You can't control which files stay in the memory,
so in daily use, you will face many cache miss to your common software,
because Windows is preferred to discard your cache for its other purpose.
Once you open your software, a lot of cache miss still result in the long first access time.
A preset loop executes interval can reload the cache for you periodic.
Result in you can always use your files that smooth like cutting butter.

prefetch's People

Contributors

mhtvssfrphde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

prefetch's Issues

Live reload ini file

Seems request safe quit read loop, this part can utilize pause variable and to trigger an event after read loop is done.

[Critical] Windows not release unused standby list even cached size is full

Steam client just downloaded a game "the witcher 2",
after that, m/prefetch report Time: 43.58 Sec every time,
even if available RAM is 24.9 GB and cached is 24.8 GB.
That shows, if cached is full, Windows won't free unused cache for new cache content.

The result is low performance. This explained why my Firefox always read from disk:
when Firefox requested cache, the cached space is full.

By use sysinternals RAMMap\File Summary, there are pack0.dzip, en0.w2speech
cached in standby list, pack0.dzip is 9.79 GB, en0.w2speech is 1.01 GB.

The computer download and update games whole night.
Until I awake and discover Firefox is slow, I never open that game before.
That shows Windows is extremely stupid to judge what are important cache to keep.
It may just a "first come, first served, until full" simple design.
New cache won't free old cache, this only happens if "in use memory" take that space.

Same situation also happen on running virtual machine,
single vmdk file can take 2~9 GB in stand by list.

Use sysinternals CacheSet to change Working set minimum to 1024 KB,
and set maximum to 204800 KB,
open a VM still left a 2.37 GB cache in standby list.

In this case, the other thing can try is once discovered standby list space
is not enough to hold all cache content, empty it before start prefetch.

I found this: https://gist.github.com/bitshifter/c87aa396446bbebeab29
it seems there is no API to selective delete cache from standby list, and only empty all?

Const command table

In this version, command are hard coded string everywhere.
Change to const variable can prevent grammar related bug.

QMenu width not update with children

    • Update qMenu size use adjustSize()
      Nothing happen
    • Update label widget size use adjustSize()
      Nothing happen
    • 1. 2. at same time
      Nothing happen
    • Label setMinimumWidth() and 1.
      Nothing happen
    • QMenu setMinimumWidth()
      Resized, but size won't reduce anymore
    • Save QMenu initial width and try restore by 5.
      Resized, but initial width is pretty wide, can't use as initial value
    • WidgetAction setDefaultWidget(label) and 1.
      Nothing happen
    • Assume QMenu initial width is 100 and manually control entire width process
      Work as intend

1.1 Road map

  • Start external exe after first prefetch d0044c6

Provide alternative to replace Windows startup manager,
to make sure these program start in cached environment.

[QUESTION] Improve Visual Studio workflow...

Hello @mhtvsSFrpHdE ,

EDIT: sorry, now I have seen this link:
https://github.com/mhtvsSFrpHdE/prefetch/wiki/Frequently-asked-questions

I have discovered recently some tools like Primocache and Ultra RAMDisk, and this repo too.
What do you think about these other alternatives pro/cons vs this prefetch repo?

My intention is to speed up a bit my Visual Studio workflow.

Some VS files are located on c:/program files, and usually the project files are in another location, and the framework/libs you are using somewhere else...
Then, the RAM disk way I am not sure that could help here,
because the files are not in the same folder,
or maybe we don't want to include many folders that could make too bigger for the available RAM memory.

What do you think about a good approach to start think the workflow?

Thanks for the repo!
Regards

New build system

  • Create all build folder if not exist before build
    • Create folder in build.py, add buildType Prepare 9ce8a55
  • VSCode run Qt lrelease to compile translate file
  • Compile several editions with different flag
    • prefetch.exe Standard version
    • prefetch_verbose.exe Standard +Log
    • prefetch_performance.exe Standard -Translate
  • Copy dll
  • Copy exe together
  • Copy translate file to pack\translate
  • Update tasks.json, launch.json example

Minimize to tray

https://rotadev.com/console-output-in-a-qt-gui-app-dev

Windows does not really support dual mode applications.

https://www.faqcode4u.com/faq/263030/hide-console-of-windows-application

A C# example shows use platform specified API to switch current console:

[DllImport("Kernel32.dll")]
  private static extern IntPtr GetConsoleWindow();
  [DllImport("User32.dll")]
  private static extern bool ShowWindow(IntPtr hWnd, int cmdShow);
   static void Main(string[] args)
  { Console.WriteLine("Press any key to hide me.");
Console.ReadKey();
IntPtr hWnd = GetConsoleWindow();
if (hWnd != IntPtr.Zero) {
ShowWindow(hWnd, 0);//hide
Thread.Sleep(5000);//5s
ShowWindow(hWnd, 1);//show } Console.ReadKey();

Custom tray menu

Open other exe to do specified things like clear standby list.
Similar to startup item, but run on user click event.
With this, many features no need to integrated to software.

RescanInterval relate definition is unclear

I personally don't use RescanInterval, so it's not covered by "user test".
Just discovered it has a wrong default value, but not trigger any bug.

After #26, the RescanInterval will change from optional to necessary.
I will ignore this config related things until that.

Try to understand the file mapping

By read these link:
https://docs.microsoft.com/en-us/windows/win32/memory/file-mapping
https://stackoverflow.com/questions/31349539/how-file-mapping-works

Here is the guess about why kernel cache will not override mapped file (virtual machine disk file):
Virtual machine programs sure not to load the entire 120 GB into system RAM,
they use address via file mapping, and when they do I/O,
Windows handle the disk access and RAM cache.

When a process does CreateFileMappingW or something, they say:
"Hey, I'm important."
During the entire system does I/O, the one created file mapping has higher priority.
Unless explicit clear standby list, they won't shrink their size in RAM until closed.

A test can give more details (doing the test, not complete yet):

  • Open RAMMap
  • Open several virtual machines to fill the standby list
  • Open several big video files to see the standby list change
  • Close the virtual machine and video player
  • Now the standby list is full and no file mapping was created. Run prefetch
  • Check performance, will either slow or fast
    • If slow, then the standby list is first come, first served, no override
    • If fast, then there is an override between cache

Fix scrollbar position when mainwindow hide->show

When MainWindow from background to foreground, there may be two or more blank line in console.
If any text update triggered, blank line will gone.
It seems background update won't trigger certain event.

If hide emit something()

2.7 Road map

  • WARNING: Drop support for fuzzy config, remove hard-coded default value
    If a config value failed to parse, no code to handle this situation anymore
    Assume config is always correct 87a783a
  • New config PrintOffset to optimal console looking c2eb933
  • Show last line of stdout in tray menu 57ebf4d
  • Tray menu: click on instance name or last line of stdout will treat as double-click on tray icon a5b1de6

2.5 Road map

  • Fix tray icon still appears after exit
  • Exit tray menu
  • Very demo quality window application
    • In order to hide window, no console anymore
    • Lacking custom font size
    • Lacking native high dpi scale
  • Minimize to tray
  • Double-click on tray icon to show or hide console
  • Start with console or only tray icon

22H2 explorer lnk hack need to use unique file name or full path

https://aka.ms/AAil99t

A test shows explorer does pass shortcut to program, but on 22H2, explorer have different rule to solve relative path:

Command "explorer.exe Firefox.lnk"

  • 21H2: explorer will look for lnk from working directory at first
  • 22H2: explorer may run lnk from start menu or somewhere else first, then working directory

Use unique lnk file name, or add full path to lnk like this:
"explorer.exe C:\Folder1\Firefox.lnk"

2.0 Roadmap

  • New approach to include program files
    72% faster than 1.x on same task, however, caused incompatible ef5db79
  • Update build system
    Merge two script into one 317a10a

Pause indeed work, but already created read thread will ignore the latest pause status

The skip variable is instance variable, and do snapshot before consume thread pool.
Thus, each file thread require another if condition on static pause variable.

Perhaps use a thread to consume thread pool, when paused, terminate it like sleep thread.

Need more investigation on how to properly run a Qt thread.
For example, currently I don't have a thread worker, but call start method directly.

Cache scan folder result

In 2.3,
unused file thread are removed after first prefetch.

I notice that the thread overhead is almost zero,
but Windows take vast of time to iterate through the file system and list all file.
This is much slower than expected.

Instead of scan all 26968 files, use a config array as cache?

What is "dbg_" unused pointer variable?

    // Delete excluded file thread
    readThreadPool->waitForDone();

    auto dbg_PendingDeleteThread = &ReadThread::pendingDeleteThread;
    for (int i = 0; i < ReadThread::pendingDeleteThread.size(); ++i)
    {
        auto threadPointer = ReadThread::pendingDeleteThread[i];
        readThreadQueue.removeOne(threadPointer);
        delete threadPointer;
    }
    ReadThread::pendingDeleteThread.clear();

In Qt Creator debugging, the local and expression window will not show,
and the debugger will not get a remote variable value.

For example, a static variable on another class is accessible, and its value is matter for debugging.
However, without this unused pointer variable, mouse hover on it shows nothing.
With this unused pointer variable, mouse hover can show the value.

2.7.1 Road map

  • Fix scrollbar position when mainwindow hide->show 308049e
  • Fix right click on tray icon can crash in early loading process 0d9f3f2
  • Const command table 123edb3
  • No safe exit: boost exit speed a little bit 646150d
    Default thread pool with block operation can cause program lost response on exit, create another one

Delete file thread once confirmed is excluded?

Now, all thread are create and save to the thread pool
if a file is excluded, the thread will run and return immediately.
Some cpu is wasted during the process

Try to delete them after excluded.

I need a dynamically size list instead of a fixed size array.

Pause, resume

True perfect pause not exist

By learn video and document, seems there were no something called "perfect pause at any time".
The implement is use cross thread variable, and tons of if statement to check the variable is changed or not.

Flavor

I personally don't like to see I do one thing a time, but do 150 times to check on a variable.

What is my pause

When I say a pause, I went to gaming or performance matter task.
After I return, I probably don't want to resume from where I left.
Only god know what's in the RAM now. I will continue to prefetch from the start point.

The only case I pause is I don't want to rescan, keep scan result in RAM.
Or I just simply close the program, later start again is also a solution.

Utilize skip variable

So the solution should be done on thread entry, I remember there is a "skip" variable.
That's a chance. The variable has an initial value on creating a thread instance.
I will get the initial value from global, instead always use "false".

Once I set global variable to "true", all new created read thread will inherit "true".
When they are fired, will return immediately and do nothing.

What to do thread runner

The thread pool runner will fire all the thread anyway.
It will change to only check global pause status once before fire any thread.
If thread pool already running, for example 47/1055,
all 1055 thread will fire, and counting on "skip" variable.

The reason mentioned before, I don't like to see every time I do something,
but first I checked a suddenly appeared variable.

Resume

I have PrefetchInterval, the one currently is use sleep on loop thread.
After send resume command, the rest of interval time should discard and do prefetch now.
So instead of sleep on the loop thread, the sleep will change to a new thread,
and loop thread will try to join the sleep thread.

In this case, when it comes to resume, I terminate the sleep thread,
prefetch will start immediately.

Safe exit

In this version, exit is just "terminate everything",
the program first run into undefined status, then exit via a crash from unknown reason.

Relative include header should not have same name

samename.cpp

#include "samename.h"
#include "B.h"

B.cpp

#include "samename.h"

I find this was really confused in some case.
They mixed with other potential bug, and can cause project failed to compile,
takes many hours to find why.

Rename the file to samename_a.h and samename_b.h.

1.3 Road map

  • Use command argument to provide ini file name 6c36b1f
  • Fix Run startup items... printed multiple times 7447a9c

When deploy multiple program instance, copy all program files to new folder is required
because now program always read prefetch.ini.

By command argument, same program instance can start with different ini file.

1.2 Road map

  • High priority include search pattern 20ced66

Firefox store its extension data along with other website data under
Profiles\default\storage\default with folder named moz-extension+++*.
However, the parent folder storage is excluded because
it's wasting of time to prefetch rare access website data.

I need to prefetch extension data, so any file path contains moz...
will have higher priority than under excluded folder.

moo easter egg command

Type command moo, draw the apt moo, text 扣1佛祖跟你一起moo,
then type command 1, draw Gautama Buddha says moo

Possible memory leak

StdIn display widget have no size limit set right not, after long time run, generated output can fill the RAM.

2.3 Road map

  • Delete excluded file thread from thread pool 7b73735
    Now, a thread optimizer may run before each round of prefetch.
    If no "delete this file" record exist, the optimizer will not run.

    The performance result is before this version, I may generate 26968 thread in total,
    most of them are empty function, return immediately, only thread overhead.
    After this version, only 155 thread fired in the second round of prefetch.

    However, don't expect huge performance gain:
    on my personal PC (E3-1231-V3), no noticeable performance different shows in benchmark result.
    This update may only try not to abuse CPU.

Internationalization | Translate

  • Qt Translate 55b657c
  • Live load different language file at runtime de437ac
  • lang en_US command
    • Split input loop to class structure, too many lines out there 96e21b8
    • Move redefine comment to translate_define.h eae330f
    • Reserve hard-coded English for speed 01dd33c
    • Load new translator, and collect together
    • Load success, uninstall exist translator
    • Append loaded translator to translator address array
    • Run init message to update string ff7d7f5
    • Trigger language change event
  • UI element response to language change event cec846b
  • Get translate folder from setting 0a57db1
  • Community how to contribute translate document url
  • Document new ini setting, Language, TranslateFolder

Auto pause

Since there is going to add pause, why not pause automatically if a certain process is running?

Rewrite build system

Currently, the build system for example

  • Build debug, copy certain file if newer
  • Pack release, pick necessary file from release folder

are draft quality, not contain any comment, unmaintainable: discovered by myself after 5 months

Result: Two script merge into one 317a10a

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.