Closed citreae535 closed 1 year ago
What's the motivation behind this pretty big restructure? Does it actually cut down the compile times in any substantial way? Are the resulting binaries smaller (even with optimizations on?)
As a very general feedback point to this PR, without having looked at the content: scm
is not a very user friendly abbreviation. I think I'd like it being spelled out as service-control-manager
. Or potentially just control-manager
if we think service
is implied. But I don't like arcane abbreviations.
A lot of restructuring, data.rs
, flags.rs
, utils.rs
are very generic names too. It begs the question, does it all really worth it?
On performance, I tested building the crate itself and the binary crate shawl
which only uses service implementation APIs and depends on windows-sys
through windows-service
. Each was repeated 3 times. The build command is cargo build --release --timings
.
Mode | Total | windows-sys | windows-service | library/binary size |
---|---|---|---|---|
lib feature on | 4s | 2.6s | 1.1s | 1274 KB |
lib feature off | 3s | 2.1s | 0.6s | 607 KB |
bin feature on | 25.99s | 7.0s | 4.0s | 2391 KB |
bin feature off | 25.76s | 5.3s | 1.5s | 2391 KB |
Disabling the feature flag when compiling the library itself cuts crate compile time by 50%
50% out of 1.1 seconds. So basically not any difference. Zero divided by two is still zero. To me that sounds like a bit too much churn for a bit too little gain.
and library size by 50%
But the binary size are the same. I guess the unused code gets shed at link time? A 50% library size difference I do think it's a great improvement! But if that size is always going to be shed off at link time anyway it's not going to make a difference in practice for anyone. Is the library in this case a shared .dll or a regular Rust rlib?
Well, Rust dylib is not easy to use, and this crate is already a wrapper to the Windows system dlls, so I don't think the size matters. I agree that this is too much effort for too little gain. Closing it now. Thanks a lot!
This draft PR tries to move SCM-related functionality behind a feature flag with as few breaking changes as possible. In its current state I think there are no breaking changes.
The commit history is a bit complicated because I tried to preserve as much blame history as possible.
Current change details
Public changes:
scm
is added. This module is enabled by a new feature flag with the same name.service::Service
andservice_manager::ServiceManager
are moved insidescm
.service
to private modulescm::data
. Public types are re-exported inscm
.service
andservice_manager
to private modulescm::flags
. They are re-exported inscm
.windows-sys
features are moved behind the feature flagscm
because they are only used inside modulescm
.Private changes:
service
are moved toscm::utils
.sc_handle::ScHandle
is renamed tocrate::scm::RawServiceHandle
. The private modulesc_handle
is removed.shell_scape
anddouble_nul_terminated
are moved insidescm
.pub(crate)
visibility modifiers are either changed topub(super)
or removed.ServiceState::from_raw
,ServiceStatus::from_raw
, andServiceStatus::from_raw_ex
are put behind the feature flagscm
because they are only used inside modulescm
. The two structs themselves are kept in place because they are used when implementing Windows services.To minimize breaking changes:
scm
is enabled by default.Unresolved questions
data.rs
andflags.rs
into a single module or shoulddata.rs
be split further?)scm
by default? Should the compatibility re-exports be kept then?scm
as a required feature)Side notes:
#[macro_use] extern crate
.Cargo.toml
asrustc-version
scm
for Windows targets only, but there's no "target-specific features" yet.This change is