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

Feature request: v8.hasFastProperties #57374

Open
Nevro opened this issue Mar 8, 2025 · 1 comment
Open

Feature request: v8.hasFastProperties #57374

Nevro opened this issue Mar 8, 2025 · 1 comment
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@Nevro
Copy link

Nevro commented Mar 8, 2025

What is the problem this feature will solve?

Obtaining an accurate threshold by which I could decide whether I want loop over object with for.in (FastProperties) or with for.keys (DictionaryProperties).

Looping over an object with fast properties is much faster (up to 5x) with for.in than with for.keys. Makes a big difference when you looping over an big object (bellow 1021 length) populated with Object.fromEntries method and even with small regular object (bellow 20 length).

What is the feature you are proposing to solve the problem?

Add hasFastProperties method to node:v8 module. This would avoid the need to expose the entire native syntax.

What alternatives have you considered?

try {
    const { setFlagsFromString } = await import('node:v8');
    setFlagsFromString('--allow-natives-syntax');
    var V8NativeSyntax = eval('%Equal(0, 0)');
} catch {
    var V8NativeSyntax = false;
}

function hasFastProperties(obj) {
    return V8NativeSyntax 
        && typeof obj === 'object'
        && eval('%HasFastProperties(obj)');
}
@Nevro Nevro added the feature request Issues that request new features to be added to Node.js. label Mar 8, 2025
@github-project-automation github-project-automation bot moved this to Awaiting Triage in Node.js feature requests Mar 8, 2025
@bnoordhuis
Copy link
Member

Not really feasible. There's no V8 C++ API1 that provides that information so Node.js cannot improve on what you're already doing.

1 And, channeling the V8 team, I'm pretty sure they won't add one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
Status: Awaiting Triage
Development

No branches or pull requests

2 participants