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

Make registry key/value iterators lazy #3260

Closed
wants to merge 2 commits into from
Closed

Conversation

riverar
Copy link
Collaborator

@riverar riverar commented Sep 5, 2024

This change updates the key and value iterators to support "forward-lazy" iteration, where the underlying key may change during the iteration process. Previously, the iterators assumed a static state for the registry key but this could lead to panic if keys were modified externally during iteration. The updated iterators now account for potential changes, at the expense of some additional registry queries and/or heap activity.

}
})
return self.next();
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 recursive - not necessarily bad in this scenario but worth calling out if it's not obvious.

Comment on lines +17 to +28
idx: 0,
name: vec![0; (info.value_name_max + 1) as usize],
data: Data::new(info.value_data_max as usize),
})
}

fn resize(&mut self) -> Result<()> {
let info = get_key_info(self.key)?;
self.name.resize((info.value_name_max + 1) as usize, 0);
self.data = Data::new(info.value_data_max as usize);
Ok(())
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a big deal but might be nice to default initialize and then call resize in the new method to avoid the redundant initialization here and in the other iterator.

for name in iterator {
if name == "one" {
key.remove_tree("three")?;
key.create("seventy")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe make it obvious that this requires a larger buffer...

let iterator = key.values()?;
for (name, value) in iterator {
if name == "string" {
key.set_string("string-two", "hello world two")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

@riverar
Copy link
Collaborator Author

riverar commented Sep 7, 2024

After more testing, I've identified a critical issue with key enumeration. Adding a subkey during this process triggers immediate lexical sorting, which can re-order the subkeys mid-enumeration. Since modification of the key isn't supported during enumeration, it's not possible to safely perform the lazy initialization proposed here. Therefore, I'm closing this PR.

@riverar riverar closed this Sep 7, 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.

2 participants