Skip to content

Refactor source cache into CachedFile struct - #12240

Merged
sholderbach merged 3 commits into
nushell:mainfrom
sholderbach:file-cache-refactor
Mar 20, 2024
Merged

sholderbach merged 3 commits into
nushell:mainfrom
sholderbach:file-cache-refactor

Conversation

@sholderbach

Copy link
Copy Markdown
Member

Description

Get rid of two parallel Vecs in StateDelta and EngineState, that also duplicated span information. Use a struct with documenting fields.

Also use Arc<str> and Arc<[u8]> for the allocations as they are never modified and cloned often (see #12229 for the first improvement). This also makes the representation more compact as no capacity is necessary.

User-Facing Changes

API breakage on EngineState/StateWorkingSet/StateDelta that should not really affect plugin authors.

Get rid of two parallel `Vec`s in `StateDelta` and `EngineState`, that
also duplicated span information. Use a struct with documenting fields.

Also use `Arc<str>` and `Arc<[u8]>` for the allocations as they are
never modified and cloned often (see nushell#12229 for the first improvement).
This also makes the representation more compact as no capacity is
necessary.
No protection, just documentation.
// Use Arcs of slice types for more compact representation (capacity less)
pub content: Arc<[u8]>,
// TODO: when refactoring `Span` to IDs this needs to remain an interval
pub covered_span: Span,

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.

You mean to keep it as Span, not converting to SpanId?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As long as we translate to Span with a global index we would need that to translate back to indices into content

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After looking how #12239 works right now I removed this particular comment, and documented the struct publicly.

@sholderbach
sholderbach merged commit ec528c0 into nushell:main Mar 20, 2024
@sholderbach
sholderbach deleted the file-cache-refactor branch March 20, 2024 18:43
@hustcer hustcer added this to the v0.92.0 milestone Mar 21, 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.

3 participants