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

lazily compute resources of DocumentStore handles #1492

Merged
merged 1 commit into from
Oct 24, 2023

Conversation

Techatrix
Copy link
Member

Instead creating the DocumentStore (and ZIR if needed) whenever the document gets modified, it is more efficient
to compute them lazily needed. This will mean that series of text edits without any requests on them which often occur while typing will be processed quicker with less latency.

I've also tested lazily computing the Ast but it turned out that the Ast was (almost) always needed which made this unnecessary.

@Techatrix Techatrix force-pushed the techatrix/lazy-documentstore branch 2 times, most recently from cb0d035 to 8b0c3c1 Compare October 6, 2023 02:30
@Techatrix Techatrix marked this pull request as ready for review October 6, 2023 04:11
@Techatrix Techatrix force-pushed the techatrix/lazy-documentstore branch 3 times, most recently from 4a91b5e to 0519e3a Compare October 15, 2023 14:56
@Techatrix Techatrix force-pushed the techatrix/lazy-documentstore branch 3 times, most recently from 10309a3 to 786ed3a Compare October 24, 2023 15:38
Instead creating the DocumentStore (and ZIR if needed) whenever the
document gets modified, it is more efficient to compute them lazily.
This will mean that series of text edits without any requests on them
which often occur while typing will be processed quicker.

I've also tested lazily computing the Ast but it turned out that the Ast
was (almost) always needed which made this unnecessary.
@Techatrix Techatrix force-pushed the techatrix/lazy-documentstore branch from 786ed3a to f9a438d Compare October 24, 2023 15:43
Copy link
Contributor

@llogick llogick left a comment

Choose a reason for hiding this comment

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

Been meaning to ask, are these intentionally not pointers (completions.zig, ~line 844)?

fn completeFileSystemStringLiteral(
    arena: std.mem.Allocator,
    store: DocumentStore,
    handle: DocumentStore.Handle,

@Techatrix
Copy link
Member Author

Ideally speaking, I would argue that pass by value should be preferred over pass by reference/pointer in zig since it gives the compiler more opportunities to optimize the code. Unfortunately in its current state, zig is sometimes failing to generate the most optimal code (#17580) but hopefully this won't be the case in the future.

This has been the main motivation why I did this. Another example of this issue would be the Config struct which is sometimes passed as a pointer and sometimes not. Despite that this is still an inconsistency in the codebase and I can change completeFileSystemStringLiteral to take its parameters as pointers if you wish.
Many uses of DocumentStore and Handle require mutability in this PR so pass by value is rarely possible anyway.

@llogick
Copy link
Contributor

llogick commented Oct 24, 2023

Nah, just me and my C mindset wondering if there was a specific technical subtlety there.

Copy link
Contributor

@llogick llogick left a comment

Choose a reason for hiding this comment

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

Should be gud .

@llogick llogick merged commit 86475a8 into master Oct 24, 2023
6 checks passed
@Techatrix Techatrix deleted the techatrix/lazy-documentstore branch October 24, 2023 19:19
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