Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Modular codegen first pass #1151

Merged
merged 12 commits into from
Sep 9, 2019
Merged

Modular codegen first pass #1151

merged 12 commits into from
Sep 9, 2019

Conversation

jamiebrynes7
Copy link
Contributor

@jamiebrynes7 jamiebrynes7 commented Sep 9, 2019

This PR implements a first pass at modular codegen which utilizes dotnet templates to assist in generating a skeleton project.

The process goes as follows:

  1. User hits code generation button.
  2. Install the dotnet template by shelling out cd $UNITY_PACKAGES_DIR/io.improbable.gdk.tools/.CodeGenTemplate/ && dotnet new -i ./
  3. Wipe $UNITY_BUILD_SCRATCH/codegen directory.
  4. Create a copy of the dotnet template: cd $UNITY_BUILD_SCRATCH/codegen && dotnet new gdk-for-unity-codegen
  5. Find all .codegen directories in packages.
  6. Edit the generated .csproj and link in any source, templates, and partials in each of the .codegen directories.
  7. Run the generated csproj.

For this first implementation, any time a user runs codegen, all the steps above happen. This has have an impact on performance of operation:

image

What particularly hurts is we lose all build artifact caching built into dotnet/msbuild since we wipe the codegen directory every time. For future optimizations, we should focus on only doing this when necessary.

Possible optimizations
  • We only need to install the dotnet template if the template has changed. For any user consuming the GDK as packages, this will only be on upgrade. For those iterating on the template semi-regularly (mostly us) this is a little harder to detect.
  • We don't need to wipe the codegen directory unless the template has changed.
  • We don't need to create a copy of the dotnet template unless the template has changed. If we can replace the blob of XML that links the packages, we can update the same .csproj file.

All of these optimizations rely on us detecting the template has changed. If we can do this, we can adjust the solution above to:

  1. User hits code generation button.
  2. Check if the template has changed.
    a. If yes, do steps 2-4 from above.
  3. Find all .codegen directories in packages.
  4. Edit the generated .csproj and link in any source, templates, and partials in each of the .codegen directories.
  5. Run the generated csproj.

This PR also contains a driveby refactor on RedirectedProcess such that the synchronous Run() now returns the RedirectedProcessResult type to make it consistent with the asynchronous one.

Remaining work

@improbable-prow-robot improbable-prow-robot added the jira/no-ticket Indicates a PR has no corresponding JIRA ticket label Sep 9, 2019
@improbable-prow-robot improbable-prow-robot added A: build-system Area: Build system feature module A: core Area: Core GDK labels Sep 9, 2019
@improbable-prow-robot improbable-prow-robot added size/XL Denotes a PR that changes 300-599 lines, ignoring generated files. A: maintenance Area: Project maintenance or hygiene A: tooling Area: Tooling labels Sep 9, 2019
@improbable-prow-robot improbable-prow-robot added the A: mobile Area: Mobile integration label Sep 9, 2019
@jamiebrynes7
Copy link
Contributor Author

jamiebrynes7 commented Sep 9, 2019

Optimization Results

  • Only Generate Code (Force) will rebuild the project from scratch.
  • We now support incrementally updating the ItemGroup containing each of the module's codegen bits.

This brought down the time from ~5000ms to ~3000ms after the first run.

Of those 3000ms, approximately 2500ms are spent inside the dotnet run -p ... command. If we wish to optimize further, I'd recommend we poke around the build & run cycle for the dotnet project rather than doing things in Unity.

@jamiebrynes7 jamiebrynes7 merged commit 677cab9 into develop Sep 9, 2019
@jamiebrynes7 jamiebrynes7 deleted the feature/modular-codegen branch September 9, 2019 16:44
jessicafalk pushed a commit that referenced this pull request Nov 15, 2019
… worker type (#1151)

* Only pack RPCs that are destined for the owning worker type of the connection (PlayerController).
* Add new method to ActorGroupManager for checking 2 actors are owned by the same worker type
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A: build-system Area: Build system feature module A: core Area: Core GDK A: maintenance Area: Project maintenance or hygiene A: mobile Area: Mobile integration A: tooling Area: Tooling jira/no-ticket Indicates a PR has no corresponding JIRA ticket size/XL Denotes a PR that changes 300-599 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants