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

Enable 64-bit registry access with 32-bit nodejs #18

Closed
vweevers opened this issue May 3, 2015 · 2 comments
Closed

Enable 64-bit registry access with 32-bit nodejs #18

vweevers opened this issue May 3, 2015 · 2 comments

Comments

@vweevers
Copy link
Owner

vweevers commented May 3, 2015

On an x64 machine:

  • If the 64-bits C:\Windows\Sysnative\cscript.exe exists, use that for registry queries. Then the bitness of nodejs won't matter anymore, and the 64-bits registry can always be accessed (without resorting to the slower ExecMethod with ProviderArchitecture flag, like node-regedit does)
  • If it doesn't exist and process.arch == "x64", find cscript in PATH and assume it's 64-bits
  • If it doesn't exist and process.arch == "ia32", find cscript in PATH and assume it's 32-bits: skip the additional Wow6432Node key searches, because the software keys will be redirected to the WoW64 registry anyway.

Another solution is detecting the bitness of the cscript executable found in PATH, with something similar to C++'s GetBinaryType or node's process.arch with PROCESSOR_ARCHITECTURE which is set to "x86" under WoW64. But this would require additional interprocess communication and another spawned process - and in the end, probably wouldn't be faster than the ExecMethod way.

Edit: let's not over-optimize. Note to self: beware of the second system effect. New plan:

  1. Find cscript with a preference for the native 64-bit version, so first in %SystemRoot%\Sysnative then in PATH. If %SystemRoot%\Sysnative\cscript.exe doesn't exist, that's a problem with the user's configuration we can't fix or foresee - so not our concern.
  2. Assume it's native (most likely) and don't skip the additional Wow6432Node key searches (just like we do now).
@vweevers
Copy link
Owner Author

vweevers commented May 3, 2015

But before that, do a quick benchmark comparing 64-bit cscript with 32-bit cscript + ExecMethod.

@vweevers
Copy link
Owner Author

vweevers commented May 4, 2015

Benchmark (comment copied from node-regedit#7)

See cscript-registry-benchmark and its output.

Calling registry.GetStringValue directly (eg, agnostic mode) is roughly 2x as fast as registry.ExecMethod_("GetStringValue", ..) with a "__ProviderArchitecture" flag / context.

The relevant bit of the output is (the third column is the difference to the agnostic duration):

Agnostic:                     2.219 sec  
64-bit:                       4.797 sec   +2.578 
64-bit (predefined method):   3.906 sec   +1.688 

As the third row shows, a small speed gain can be made by reusing the method object:

' Initialize
set method = registry.Methods_("GetStringValue")

' Then later ..
Set params = method.Inparameters
params.hDefKey = ..

Instead of doing registry.Methods_("GetStringValue").Inparameters each time.

PS. You might see "20000 sec" in the output, that's a formatting mistake, should be 2 seconds.

@vweevers vweevers changed the title 64-bit registry access with 32-bit nodejs Enable 64-bit registry access with 32-bit nodejs May 4, 2015
vweevers added a commit that referenced this issue May 5, 2015
@vweevers vweevers closed this as completed May 5, 2015
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

No branches or pull requests

1 participant