Skip to content

Commit 1374281

Browse files
authored
chore: improve bench (#177)
1 parent 4fa1521 commit 1374281

37 files changed

+313
-195
lines changed

README.md

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<a href="https://sharp.elringus.com" target="_blank" rel="noopener noreferrer">
2+
<a href="https://bootsharp.com" target="_blank" rel="noopener noreferrer">
33
<img width="200" src="https://raw.githubusercontent.com/elringus/bootsharp/main/docs/public/favicon.svg" alt="Bootsharp">
44
</a>
55
</p>
@@ -14,10 +14,12 @@
1414

1515
# Use C# in web apps with comfort
1616

17-
Bootsharp streamlines consuming .NET C# apps and libraries in web projects. It's ideal for building web applications, where domain (backend) is authored in .NET C#, while the UI (frontend) is a standalone TypeScript or JavaScript project. Think of it as [Embind](https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html) for C++ or [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) for Rust.
17+
Bootsharp streamlines the integration of .NET C# apps and libraries into web projects. It's ideal for building applications where the domain (backend) is authored in .NET C#, while the UI (frontend) is a standalone TypeScript or JavaScript project. Think of it as [Embind](https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html) for C++ or [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) for Rust.
1818

1919
![](https://raw.githubusercontent.com/elringus/bootsharp/main/docs/public/img/banner.png)
2020

21+
Facilitating high-level interoperation between C# and TypeScript, Bootsharp lets you build the UI layer within its natural ecosystem using industry-standard tooling and frameworks, such as [React](https://react.dev) and [Svelte](https://svelte.dev). The project can then be published to the web or bundled as a native desktop or mobile application with [Electron](https://electronjs.org) or [Tauri](https://tauri.app).
22+
2123
## Features
2224

2325
✨ High-level C# <-> TypeScript interop
@@ -32,75 +34,8 @@ Bootsharp streamlines consuming .NET C# apps and libraries in web projects. It's
3234

3335
🛠️ Allows customizing emitted bindings
3436

35-
🔥 Supports WASM multi-threading, AOT, trimming
36-
37+
🔥 Supports multi-threading, NativeAOT-LLVM, trimming
3738

3839
## 🎬 Get Started
3940

40-
https://sharp.elringus.com/guide/getting-started
41-
42-
### Why not Blazor?
43-
44-
In contrast to solutions like Blazor, which attempt to bring the entire web platform inside .NET, Bootsharp facilitates high-level interoperation between C# and TypeScript, allowing to build the UI layer under its natural ecosystem using industry-standard tooling and frameworks, such as [React](https://react.dev) and [Svelte](https://svelte.dev).
45-
46-
### Why not `System.JavaScript`?
47-
48-
Bootsharp itself is built on top of [System.Runtime.InteropServices.JavaScript](https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/import-export-interop?view=aspnetcore-8.0) introduced in .NET 7.
49-
50-
If you need to expose a simple library API to JavaScript and don't require type declarations, Bootsharp is probably overkill. However, .NET's interop is low-level, lacks support for passing custom types by value, and requires extensive boilerplate to define bindings, making it impractical for large API surfaces.
51-
52-
With Bootsharp, you can simply provide your domain-specific interfaces and use them seamlessly on the other side, as if they were originally authored in TypeScript (and vice versa). This ensures a clear separation of concerns: your domain codebase won't be aware of the JavaScript environment—no need to annotate methods for interop or specify marshalling hints for arguments.
53-
54-
For example, consider the following abstract domain code:
55-
56-
```cs
57-
public record Data (string Info, IReadOnlyList<Item> Items);
58-
public record Result (View Header, View Content);
59-
public interface IProvider { Data GetData (); }
60-
public interface IGenerator { Result Generate (); }
61-
62-
public class Generator (IProvider provider) : IGenerator
63-
{
64-
public Result Generate ()
65-
{
66-
var data = provider.GetData();
67-
// Process the data and generate result.
68-
return result;
69-
}
70-
}
71-
```
72-
— the code doesn't use any JavaScript-specific APIs, making it fully testable and reusable. To expose it to JavaScript, all we need to do is add the following to `Program.cs` in a separate project for the WASM target:
73-
74-
```cs
75-
using Bootsharp;
76-
using Bootsharp.Inject;
77-
using Microsoft.Extensions.DependencyInjection;
78-
79-
[assembly: JSImport(typeof(IProvider))]
80-
[assembly: JSExport(typeof(IGenerator))]
81-
82-
// Bootsharp auto-injects implementation for 'IProvider'
83-
// from JS and exposes 'Generator' APIs to JS.
84-
new ServiceCollection()
85-
.AddBootsharp()
86-
.AddSingleton<IGenerator, Generator>()
87-
.BuildServiceProvider()
88-
.RunBootsharp();
89-
```
90-
91-
— we can now provide implementation for `IProvider` and use `Generator` in JavaScript/TypeScript:
92-
93-
```ts
94-
import bootsharp, { Provider, Generator } from "bootsharp";
95-
96-
// Implement 'IProvider'.
97-
Provider.getData = () => ({
98-
info: "...",
99-
items: []
100-
});
101-
102-
await bootsharp.boot();
103-
104-
// Use 'Generator'.
105-
const result = Generator.generate();
106-
```
41+
https://bootsharp.com/guide

docs/.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@ export default defineConfig({
7575
"/api/": [{ text: "Reference", items: (await import("./../api/typedoc-sidebar.json")).default }]
7676
}
7777
},
78-
sitemap: { hostname: "https://sharp.elringus.com" }
78+
sitemap: { hostname: "https://bootsharp.com" }
7979
});

docs/guide/getting-started.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public static partial class Program
4646
}
4747
```
4848

49+
::: info NOTE
50+
Authoring interop via static methods is impractical for large API surfaces—it's shown here only as a simple way to get started. For real projects, consider using [interop interfaces](/guide/interop-interfaces) instead.
51+
:::
52+
4953
## Compile ES Module
5054

5155
Run following command under the solution root:

docs/guide/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
## What?
44

5-
Bootsharp is a solution for building web applications, where domain is authored in .NET C# and is consumed by a standalone JavaScript or TypeScript project.
5+
Bootsharp is a solution for building web applications where the domain logic is authored in .NET C# and consumed by a standalone JavaScript or TypeScript project.
66

77
## Why?
88

9-
C# is a popular language for building maintainable software with complex domain logic, such as enterprise and financial applications. However, its frontend capabilities are lacking, especially compared to the web ecosystem.
9+
C# is a popular language for building maintainable software with complex domain logic, such as enterprise and financial applications. However, its frontend capabilities are lackingespecially when compared to the web ecosystem.
1010

11-
Web platform is the industry-standard for building modern user interfaces. It has best in class tooling and frameworks, such as [React](https://react.dev) and [Svelte](https://svelte.dev) — allowing to build better frontends faster, compared to any other language/platform ecosystem.
11+
The web platform is the industry standard for building modern user interfaces. It offers best-in-class tooling and frameworks, such as [React](https://react.dev) and [Svelte](https://svelte.dev), enabling developers to build better frontends faster than with any other language or platform.
1212

13-
In contrast to solutions like [Blazor](https://dotnet.microsoft.com/en-us/apps/aspnet/web-apps/blazor), which attempt to bring the entire web platform inside .NET (effectively reversing natural workflow), Bootsharp facilitates high-level interoperation between C# and TypeScript, allowing to build domain and UI layers under their natural ecosystems.
13+
In contrast to solutions like [Blazor](https://dotnet.microsoft.com/en-us/apps/aspnet/web-apps/blazor), which attempt to bring the entire web platform into .NET (effectively reversing the natural workflow), Bootsharp facilitates high-level interoperation between C# and TypeScript. This allows you to build the domain and UI layers within their natural ecosystems. The project can then be published to the web or bundled as a native desktop or mobile application with [Electron](https://electronjs.org) or [Tauri](https://tauri.app).
1414

1515
## How?
1616

17-
Bootsharp installs as a [NuGet package](https://www.nuget.org/packages/Bootsharp) to the C# project dedicated for building the solution for web. It's specifically designed to not "leak" the dependency outside entry assembly of the web target, which is essential to keep the domain clean from any platform-specific details.
17+
Bootsharp is installed as a [NuGet package](https://www.nuget.org/packages/Bootsharp) into the C# project dedicated to building the solution for the web. It is specifically designed not to "leak" the dependency outside the entry assembly of the web targetessential for keeping the domain clean of any platform-specific details.
1818

19-
While it's possible to author both export (C# -> JS) and import (C# <- JS) bindings via static methods, complex solutions will benefit from interface-based interop: simply feed Bootsharp C# interfaces describing export and import API surfaces, and it will automatically generate associated bindings and type declarations.
19+
While it's possible to author both export (C# JS) and import (C# JS) bindings via static methods, complex solutions benefit from interface-based interop. Simply provide Bootsharp with C# interfaces describing the export and import API surfaces, and it will automatically generate the associated bindings and type declarations.
2020

2121
![](/img/banner.png)
2222

23-
Bootsharp will automatically build and bundle JavaScript package when publishing C# solution, as well as generate `package.json`, so that you can reference the whole C# solution as any other ES module in your web project.
23+
Bootsharp will automatically build and bundle the JavaScript package when publishing the C# solution, and generate a `package.json`, allowing you to reference the entire C# solution as any other ES module in your web project.
2424

2525
::: code-group
2626
```jsonc [package.json]

docs/guide/interop-interfaces.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Interop Interfaces
22

3-
Instead of manually authoring a binding for each method, make Bootsharp generate them automatically with `[JSImport]` and `[JSExport]` assembly attributes.
3+
Instead of manually authoring a binding for each method, let Bootsharp generate them automatically using the `[JSImport]` and `[JSExport]` assembly attributes.
44

5-
For example, say we have a JavaScript UI (frontend), which needs to be notified when a data is mutated on the C# domain layer (backend), so it can render the updated state; additionally, our frontend may have a setting (eg, stored in browser cache) to temporary mute notifications, which needs to be retrieved by the backend. Create the following interface in C# to describe the expected frontend APIs:
5+
For example, say we have a JavaScript UI (frontend) that needs to be notified when data is mutated in the C# domain layer (backend), so it can render the updated state. Additionally, the frontend may have a setting (e.g., stored in the browser cache) to temporarily mute notifications, which the backend needs to retrieve. You can create the following interface in C# to describe the expected frontend APIs:
66

77
```csharp
88
interface IFrontend
@@ -12,28 +12,15 @@ interface IFrontend
1212
}
1313
```
1414

15-
Now add the interface type to the JS import list:
15+
Now, add the interface type to the JS import list:
1616

1717
```csharp
1818
[assembly: JSImport([
1919
typeof(IFrontend)
2020
])]
2121
```
2222

23-
Bootsharp will generate following C# implementation:
24-
25-
```csharp
26-
public static partial class JSFrontend : IFrontend
27-
{
28-
[JSFunction] public static partial void NotifyDataChanged (Data data);
29-
[JSFunction] public static partial bool IsMuted ();
30-
31-
void IFrontend.NotifyDataChanged (Data data) => NotifyDataChanged(data);
32-
bool IFrontend.IsMuted () => IsMuted();
33-
}
34-
```
35-
36-
— which you can use in C# to interop with the frontend and following TypeScript spec to be implemented on the frontend:
23+
Bootsharp will automatically implement the interface in C#, wiring it to JavaScript, while also providing you with a TypeScript spec to implement on the frontend:
3724

3825
```ts
3926
export namespace Frontend {
@@ -42,7 +29,7 @@ export namespace Frontend {
4229
}
4330
```
4431

45-
Now say we want to provide an API for frontend to request mutation of the data:
32+
Now, say we want to provide an API for the frontend to request a mutation of the data:
4633

4734
```csharp
4835
interface IBackend
@@ -59,7 +46,7 @@ Export the interface to JavaScript:
5946
])]
6047
```
6148

62-
Get the following implementation auto-generated:
49+
This will generate the following implementation:
6350

6451
```csharp
6552
public class JSBackend
@@ -76,16 +63,16 @@ public class JSBackend
7663
}
7764
```
7865

79-
— which will produce following spec to be consumed on JavaScript side:
66+
— which will produce the following spec to be consumed on the JavaScript side:
8067

8168
```ts
8269
export namespace Backend {
8370
export function addData(data: Data): void;
8471
}
8572
```
8673

87-
To make Bootsharp automatically inject and inititliaize generate interop implementations, use [dependency injection](/guide/extensions/dependency-injection) extension.
74+
To make Bootsharp automatically inject and initialize the generated interop implementations, use the [dependency injection](/guide/extensions/dependency-injection) extension.
8875

8976
::: tip Example
90-
Find example on using interop interfaces in the [React sample](https://github.com/elringus/bootsharp/tree/main/samples/react).
77+
Find an example of using interop interfaces in the [React sample](https://github.com/elringus/bootsharp/tree/main/samples/react).
9178
:::

docs/index.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ titleTemplate: Bootsharp • :title
77
hero:
88
name: Bootsharp
99
text: Use C# in web apps with comfort
10-
tagline: Author domain in C#, while taking full advantage of the modern JavaScript frontend ecosystem.
10+
tagline: Author the domain in C#, while fully leveraging the modern JavaScript frontend ecosystem.
1111
actions:
1212
- theme: brand
1313
text: Get Started
@@ -31,7 +31,7 @@ hero:
3131
<div class="icon">✨</div>
3232
<h2 class="title">High-level Interoperation</h2>
3333
</div>
34-
<p class="details">Generates JavaScript bindings and type declarations for your C# APIs facilitating seamless interop between the domain and UI.</p></article>
34+
<p class="details">Generates JavaScript bindings and type declarations for your C# APIs, enabling seamless interop between domain and UI.</p></article>
3535
</div>
3636
</div>
3737
<div class="grid-3 item">
@@ -41,7 +41,7 @@ hero:
4141
<div class="icon">📦</div>
4242
<h2 class="title">Embed or Sideload</h2>
4343
</div>
44-
<p class="details">Choose between embedding all the C# binaries into single-file ES module for portability or sideload for best performance and build size.</p></article>
44+
<p class="details">Choose between embedding all C# binaries into a single-file ES module for portability or sideloading for performance and size.</p></article>
4545
</div>
4646
</div>
4747
<div class="grid-3 item">
@@ -51,7 +51,7 @@ hero:
5151
<div class="icon">🗺️</div>
5252
<h2 class="title">Runs Everywhere</h2>
5353
</div>
54-
<p class="details">Node, Deno, Bun, web browsers and even constrained environments, such as VS Code extensionsyour app will work everywhere.</p></article>
54+
<p class="details">Node, Deno, Bun, web browserseven constrained environments like VS Code extensionsyour app runs everywhere.</p></article>
5555
</div>
5656
</div>
5757
</div>
@@ -63,7 +63,7 @@ hero:
6363
<div class="icon">⚡</div>
6464
<h2 class="title">Interop Interfaces</h2>
6565
</div>
66-
<p class="details">Manually author interop APIs via static C# methods or simply feed Bootsharp your domain-specific interfacesit'll figure the rest.</p></article>
66+
<p class="details">Manually author interop APIs via static C# methods or feed Bootsharp your domain-specific interfacesit'll handle the rest.</p></article>
6767
</div>
6868
</div>
6969
<div class="grid-4 item">
@@ -73,7 +73,7 @@ hero:
7373
<div class="icon">🏷️</div>
7474
<h2 class="title">Instance Bindings</h2>
7575
</div>
76-
<p class="details">When an interface value is specified in interop API, instance binding is generated allowing to interoperate on stateful objects.</p></article>
76+
<p class="details">When an interface value is used in interop, instance binding is generated to interoperate with stateful objects.</p></article>
7777
</div>
7878
</div>
7979
<div class="grid-4 item">
@@ -83,7 +83,7 @@ hero:
8383
<div class="icon">🛠️</div>
8484
<h2 class="title">Customizable</h2>
8585
</div>
86-
<p class="details">Configure namespaces for emitted bindings, function and event names, C# -> TypeScript type mappings and more.</p></article>
86+
<p class="details">Configure namespaces for emitted bindings, function and event names, C# -> TypeScript type mappings, and more.</p></article>
8787
</div>
8888
</div>
8989
<div class="grid-4 item">
@@ -93,7 +93,7 @@ hero:
9393
<div class="icon">🔥</div>
9494
<h2 class="title">Modern .NET</h2>
9595
</div>
96-
<p class="details">Supports latest runtime features: WASM multi-threading, AOT compilation, assembly trimming, streaming module instantiation.</p></article>
96+
<p class="details">Supports latest runtime features: WASM multi-threading, assembly trimming, NativeAOT-LLVM, streaming instantiation.</p></article>
9797
</div>
9898
</div>
9999
</div>

docs/public/img/llvm-bench.png

10.9 KB
Loading

0 commit comments

Comments
 (0)