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

feat: engine setup #24

Closed
wants to merge 21 commits into from
Closed

feat: engine setup #24

wants to merge 21 commits into from

Conversation

sno2
Copy link
Contributor

@sno2 sno2 commented Jul 24, 2023

This is greatly inspired by Kiesel and SerenetyOS's LibJS JavaScript engines.

This is greatly inspired by Kiesel and SerenetyOS's LibJS JavaScript
engines.
nova_vm/src/types.rs Outdated Show resolved Hide resolved
Co-authored-by: Aapo Alasuutari <[email protected]>
@ghost ghost self-requested a review July 24, 2023 16:56
Co-authored-by: Aapo Alasuutari <[email protected]>
Copy link
Collaborator

@aapoalas aapoalas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll mark as Request changes since I'm not particularly thrilled about 90% of my heap code being simply removed :) I'll try leave more comments tomorrow.

nova_vm/src/heap/object.rs Outdated Show resolved Hide resolved
nova_vm/src/small_integer.rs Outdated Show resolved Hide resolved
nova_vm/src/small_string.rs Show resolved Hide resolved
nova_vm/src/small_string.rs Outdated Show resolved Hide resolved
#[derive(Debug)]
pub struct DeclarativeEnvironment {
pub outer_env: Option<Environment>,
pub bindings: HashMap<&'static str, Binding>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: I think the keys may benefit from being Value::Strings. After all, often a binding key will also find its way into a map key etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I'd actually personally probably set these up as ParallelVecs with one Vec for keys, one Vec for values and then probably one for the rest. It's quite possible that we end up with better perf iterating through a vector of keys than hopping through a HashMap linked list. This especially so since the iteration will likely be aggressively unrolled and SIMD'd.

And the reason for separating keys from values is that usually we're looking for a single item by key: If we iterate key-value pairs then all but once the value bytes are entirely wasted and we waste cache line space. Only once do we actually hit the right key and we know where we hit it by our iteration index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion. I had added the &'static str to avoid lifetimes while copying the spec entities but this would be better. Will work on implementing this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ParallelVecs in question should be sorted, and all code should appropriately use logarithmic lookups (stdlib has us covered here with slice methods).

If we're to do away with HashMaps entirely for some parts of the code*, we should have a generic type built on ParallelVec for reuse.

* There are other hash map types and algorithms and allocator configurations? Maybe those would be more suitible? A HashMap in an arena allocator for example. I believe there are already libraries for this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declarative_record: Rc<RefCell<DeclarativeEnvironment>>,

/// [[VarNames]]
var_names: HashMap<&'static str, ()>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Use a vector.

Thanks to Phosra for figuring out I messed up descriptor logic.
/// %Array%
pub fn array() -> Object {
Object::new(Value::Object(Handle::new(
BuiltinObjectIndexes::ArrayConstructorIndex as u32,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect: The constructor should be a function and the arrayconstructorindex is the index of the function's heap object data which the function heap data refers to. I had the get_constructor_index function somewhere on the heap constants file that translates the built-in object heap data index into the corresponding function index.

nova_vm/src/execution/realm/intrinsics.rs Outdated Show resolved Hide resolved
nova_vm/src/language/script.rs Show resolved Hide resolved
nova_vm/src/small_integer.rs Outdated Show resolved Hide resolved
@aapoalas
Copy link
Collaborator

I rebased and merged this in #28

@aapoalas aapoalas closed this Oct 15, 2023
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.

2 participants