Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework windows "Physical size" calculation, added Unit Tests #9

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

Mart-Bogdan
Copy link
Contributor

Added:

  1. Unit tests
  2. Github workflow to run:
    • Tests
    • clippy
    • code formatting checks
  3. Changed implementation on windows. Fixes Deal with max path size on Windows #5.

Current implementation provides more correct size for files of size around 2k
and would show it as 4k physical size. CompressedFileSize would report smaller size.

But it still have problems of being inconsistent with Windows explorer for files smaller than 512 bytes.
Such small files are actually stored inside directory, not in own clusters, and explorer reports them as 0.

Actual threshold is not 512, it's dynamic, for now I don't know how to detect it.

Also this algorithm ignores alternate data streams. Same for previous implementation.
To be more precise -- alternate data streams can also be compressed, as I learned recently.

Main difference: we are using syscall that uses file handle (that we already have opened) instead of getting by file path.
And getting file path for long path required reformatting path into special format. Rust's std File is performing this for us under the hood. I first tried to fix this, and format string with \\.\ prefix (for network path UNC prefix) to enable long path, but that's big tricky function that have to be maintained, and using GetFileInformationByHandleEx gives us more flexibility for further improvements.

* Manually implemented windows File Namespace name generation

* added some unit tests

closes scullionw#5
Current implementation provides more correct size for files of size around 2k
and would show it as 4k physical size. CompressedFileSize would report smaller size.

But it still have problems of being inconsitent with Windows explorer for files smaller than 512 bytes.
Such small files are actually stored inside directory, not in own clusters, and explorer reports them as 0.

Actual threshold is not 512, it's dynamic, for now I don't know how to detect it.

Also this algorithm ignores alternate data streams. Same for previous implementation.
To be more precise -- alternate data streams can also be compressed, as I learned today.
…s for windows

Use COMPRESSION_FORMAT_LZNT1 instead of COMPRESSION_FORMAT_DEFAULT, perhaps it would help on WinServer
…version

as it was accidentally increased twice, skiping one version number.
@Mart-Bogdan
Copy link
Contributor Author

It has lots of clippy warnings, but I think they should be resolved by separate PR. And then we can even reject PRs that don't stratify clippy.

@Mart-Bogdan
Copy link
Contributor Author

I have written simple benchmark, and it shows that this solution is even faster:

https://github.com/Mart-Bogdan-TMP/dirstat-rs-benchmark/actions/runs/3504907900/jobs/5870888010

physical size/new       time:   [341.84 ms 348.53 ms 356.52 ms]
physical size/old       time:   [595.32 ms 603.11 ms 611.31 ms]
logical size/new        time:   [330.95 ms 332.91 ms 334.89 ms]
logical size/old        time:   [343.66 ms 345.34 ms 347.08 ms]

But we need to take this tests with grain of salt. It only measures functions/syscall overhead. Filesystem cache takes most on itself.

(if we want to exclude FS cache from equation, we would need another testing methodology, that would flush caches. It's possible, at least on Linux).

On my local machine I've got following results:

physical size/new       time:   [128.04 ms 128.74 ms 129.44 ms]
physical size/old       time:   [161.32 ms 162.06 ms 162.83 ms]
logical size/new        time:   [130.70 ms 131.47 ms 132.24 ms]
logical size/old        time:   [131.18 ms 131.90 ms 132.64 ms]

@Mart-Bogdan
Copy link
Contributor Author

Hello, @scullionw. Can you please review my PR?

@scullionw
Copy link
Owner

Hi! Thanks for the PR!

Sorry about the delays, quite busy these days. This is a pretty big one and I can't review it all right now.

However, if you want to split the PR (tests, workflows, changes to windows impl), we can merge the first two!

@Mart-Bogdan
Copy link
Contributor Author

Hi.
Hm. I guess it's possible. Would need to split tests for new functionality out.

Could try it till Friday.

P.S. wanted to work on other stuff regarding this app as well.

@Mart-Bogdan
Copy link
Contributor Author

image
Tests are failing without code. I guess I would not commit in not working tests.

@Mart-Bogdan
Copy link
Contributor Author

I have created PR #10 with tests

higersky added a commit to higersky/dirstat-rs that referenced this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deal with max path size on Windows
2 participants