Skip to content

Fix #7760 Use nu_engine::get_config in core code paths#10483

Closed
jakeswenson wants to merge 3 commits intonushell:mainfrom
jakeswenson:fix/7760/use-nu-engine-get-config-in-core-code-paths
Closed

Fix #7760 Use nu_engine::get_config in core code paths#10483
jakeswenson wants to merge 3 commits intonushell:mainfrom
jakeswenson:fix/7760/use-nu-engine-get-config-in-core-code-paths

Conversation

@jakeswenson
Copy link
Copy Markdown

@jakeswenson jakeswenson commented Sep 23, 2023

Description

This PR fixes #7760 and updates the usage of EngineState::get_config to nu_engine::get_config in some core places in nu. There are still many many more places that use get_config ...

User-Facing Changes

  • None, overlays now properly can add hooks in

Tests + Formatting

Need advice on testing this. This was something that was very difficult to test since this seems to reproduce only when the config file is set. the test framework for the testbin nu_repl needs a significant rewrite in order to make this testable, and doesn't actually test using the real REPL..

After Submitting

N/A - just a bug fix

fixes #7760

@sholderbach sholderbach requested a review from kubouch September 25, 2023 16:21
parts.push(eval_expression(engine_state, stack, expr)?);
}

// TODO: Should this move to nu_engine::env::get_config?
Copy link
Copy Markdown
Contributor

@kubouch kubouch Sep 25, 2023

Choose a reason for hiding this comment

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

Yes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, this is a good place to watch out for performance: Running string interpolation in a hot loop would likely be slower with cloning the config. It might be worthwhile changing the nu_engine::env::get_config to output a Cow, or something like that—that could be a separate PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cow<'a, T> comes with a lifetime and optimizes for potential writes at the call.

Sounds like a situation for the Arc<T> if it only needs reads (I assume we need Send/Sync for par-each?) or Arc<Mutex<T>> if we need a writeable config.

But yeah benchmarking is probably the first step with something like this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The problem is that nu_engine::env::get_config() can return either a reference, or an owned value, depending on whether it comes from the stack or the engine.

@kubouch
Copy link
Copy Markdown
Contributor

kubouch commented Sep 25, 2023

You should be able to test it by running something like $env.config.xxx = yyy; run-something-that-requires-the-config-setting. Without your fix, you'd observe that run-something-that-requires-the-config-setting won't work as expected because the config is not updated. After your fix, it should work. It might be hard to test all the cases.

We should also watch out for performance because now we're cloning the config every time. You could, for example, keep track of the startup time—if it rises, we could look into optimizing it.

And finally, you don't need to convert every single instance of get_config(), it depends on your stamina :-D.

@jakeswenson
Copy link
Copy Markdown
Author

Closing this PR in favor of the changes in #10613

Thanks for all the discussion @kubouch and @sholderbach! I hope you do mind moving it to the new PR!

@jakeswenson jakeswenson closed this Oct 5, 2023
@jakeswenson jakeswenson deleted the fix/7760/use-nu-engine-get-config-in-core-code-paths branch October 5, 2023 06:41
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.

Overlay hooks don't work unless another hook is registered from command line

3 participants