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

Parcel V3 - Native asset request #9808

Merged
merged 18 commits into from
Jun 19, 2024
Merged

Parcel V3 - Native asset request #9808

merged 18 commits into from
Jun 19, 2024

Conversation

mattcompiles
Copy link
Contributor

This PR adds the initial logic for a native AssetRequest. Highly inspired by @devongovett's core-rs2 branch.

I haven't added any tests as yet and I'm a little unsure about whether they're worth it. Unlike the path request, this request needs access to the entire plugins struct which is currently painful to mock/simulate. Happy to be guided here if peeps have bright ideas to solve this.

There's still a bunch of TODO's left to resolve. We can address them now through the PR comments or come back to them later. I think the code will be easier to revisit once the transformers are in a working place.

@@ -150,9 +155,20 @@ impl Asset {
}
}

impl Hash for Asset {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we unable to derive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this as we no longer need it to be hashable

) -> Result<RequestResult<AssetResult>, RunRequestError> {
request_context.report(ReporterEvent::BuildProgress(BuildProgressEvent::Building(
AssetBuildEvent {
// TODO: Should we try avoid a clone here?
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally it'll be fine to clone.

If we find either copying memory or, more likely, memory allocation are a bottleneck, we can optimise easily for all read-only types using references or interning, but without having to spread lifetimes throughout.

Copy link
Member

Choose a reason for hiding this comment

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

you'll want interning, it makes a big difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address interning in a later PR

TransformationInput::Asset(asset) => asset.file_path(),
}
}

pub fn read_source_code(&self, fs: FileSystemRef) -> anyhow::Result<Rc<SourceCode>> {
pub fn read_source_code(self, fs: FileSystemRef) -> anyhow::Result<Rc<SourceCode>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

why does it consume self? you'd want to store Option<Rc<SourceCode>> in the initial asset to prevent consuming things here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a typo actually I think 😅

}

pub fn validators(&self, _path: &Path) -> Result<Vec<Box<dyn ValidatorPlugin>>, anyhow::Error> {
todo!()
}
}

pub struct TransformerPipeline {
pub transformers: Vec<Box<dyn TransformerPlugin>>,
Copy link
Member

Choose a reason for hiding this comment

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

Still think this could just be a list of plugin names from the config that could be "loaded" on demand as they are run.

) -> Result<RequestResult<AssetResult>, RunRequestError> {
request_context.report(ReporterEvent::BuildProgress(BuildProgressEvent::Building(
AssetBuildEvent {
// TODO: Should we try avoid a clone here?
Copy link
Member

Choose a reason for hiding this comment

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

you'll want interning, it makes a big difference.


let result = run_pipeline(
pipeline,
TransformationInput::InitialAsset(InitialAsset {
Copy link
Member

Choose a reason for hiding this comment

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

Can the input to a transformer always be an asset? Ideally transformers shouldn't know or care that they are first in a pipeline

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea here is to abstract this away via methods, but definitely happy to iterate on this design.

let content_key = result.asset.id().to_string();
self
.cache
.set_blob(&content_key, result.asset.source_code.bytes())?;
Copy link
Member

Choose a reason for hiding this comment

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

source_code is confusing since it's not source anymore it's compiled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, renamed to Code

// TODO: move the following to RunRequestContext
pub cache: CacheRef,
pub file_system: FileSystemRef,
pub plugins: Arc<Plugins<'a>>,
Copy link
Member

Choose a reason for hiding this comment

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

I think this isn't quite ideal because it represents the entire config? So if you change the .parcelrc but only the packagers section for example, it'll invalidate all of the asset requests too. In my branch I only pass through a reference to the transformers section to avoid this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were thinking that plugins would be tracked via invalidations rather than via the request id/hash. This is why I haven't added them to the hash

self.pipeline.hash(state);
self.env.hash(state);
self.side_effects.hash(state);
}
Copy link
Member

Choose a reason for hiding this comment

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

Missing plugins? Should invalidate the request when the config changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, we will address this later either with invalidations or by including the transformers in the hash.

@mattcompiles mattcompiles merged commit 70c6d5f into v2 Jun 19, 2024
16 of 17 checks passed
@mattcompiles mattcompiles deleted the native-asset-request branch June 19, 2024 02:57
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.

None yet

3 participants