Skip to content

Split Sample App Shared Infrastructure between Experiment / All #122

Open

Description

@michael-hawker

Current Infrastructure

Right now when we run an experiment or run the whole sample app, the same CommunityToolkit.Labs.Shared project is used to generate the application shell itself. In it's App.xaml.cs file we detect with a build constant LABS_ALL_SAMPLES from the generated Labs.SampleRefs.props file to see if we should pick the TabbedPage or the NavigationPage to display whichever pages/docs we want to see based on the rest of the included dependencies.

Potential Performance Problem

As we expand the scope of the all-up sample app, we may include more source generators or components like search indexers or the like that aren't needed when developing a single experiment's samples and docs. If this becomes and issue we may want to separate these things out when building an experiment.

Solution

We should be able to do this later, as all the infrastructure is shared and abstracted away from the experiments already.

In each of the all solutions heads we reference the generated Labs.SampleRefs.props file first then the Labs.Head.props file:

<Import Project="$(RepositoryDirectory)common\Labs.SampleRefs.props" />
<Import Project="$(RepositoryDirectory)common\Labs.Head.props" />

Therefore in the Labs.Heads.props file we should have access to the LABS_ALL_SAMPLES constant here:

<Import Project="$(RepositoryDirectory)\common\CommunityToolkit.Labs.Shared\CommunityToolkit.Labs.Shared.projitems" Label="Shared" />

(The source generators are referenced lower down as well, so if we have different sets, I think similar logic will apply.)

So, instead of having a single CommunityToolkit.Labs.Shared.projitems we create two files a CommunityToolkit.Labs.Shared.Experiment and a CommunityToolkit.Labs.Shared.All for instance. These two projects may share some common components (like our Renderers) on disk, but be able to include only the components needed for each experience.

<Choose>
    <When Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(
         $(DefineConstants), '^(.*;)*LABS_ALL_SAMPLES(;.*)*$'))">
         <Import Project="$(RepositoryDirectory)\common\CommunityToolkit.Labs.Shared\CommunityToolkit.Labs.Shared.All.projitems" Label="Shared" />
    </When>
    <Otherwise>
         <Import Project="$(RepositoryDirectory)\common\CommunityToolkit.Labs.Shared\CommunityToolkit.Labs.Shared.Experiment.projitems" Label="Shared" />
    </Otherwise>
</Choose>

Regex from docs here

Though we could also just define an MSBuild property and switch on that too or something.

Activity

  1. added
    enhancement
    dev loop ➰
    on May 13, 2022
  2. added this to the Future milestone on May 13, 2022
  3. Arlodotexe commented on May 17, 2022

    @Arlodotexe
    Member

    Pulling over a conversation from Discord for history:

    From @Arlodotexe

    I'm still not sure I understand why we want to split the Shared infrastructure in 2, when we're already pulling in only the relevant content at compile time (markdown, referenced sample controls)
    When building CanvasLayout for example, it can't even see other experiments unless you're in the All solution.

    From @michael-hawker

    If it's negligible on compile time and load time, then it's not a problem. Though if it saves us a few seconds, having a tighter inner devloop would be worth it.

    From @Arlodotexe

    Right, I'm wary of that because

    • We've already done careful job of planning the infrastructure so this doesn't become an issue, so we've got a rather nice thing set up.
    • It's a complex refactor
    • The only benefit I can think of, is that it excludes some of the pages that aren't used by the single Experiment head arent compiled or included in the final binary

    and I think that last thing could be solved without splitting our codebase

    Feels like a sweeping solution to something that could end up just being a bugfix or improvement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dev loop ➰enhancementsample app 🖼

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions