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

Reduce bundle size increase to zero :) #1

Closed
MangelMaxime opened this issue Jul 21, 2019 · 9 comments
Closed

Reduce bundle size increase to zero :) #1

MangelMaxime opened this issue Jul 21, 2019 · 9 comments

Comments

@MangelMaxime
Copy link
Contributor

By looking at the source code Feliz is using class with a constructor.

module Test

type IBorderStyle = interface end

type borderStyle() =
    static member inline dotted : IBorderStyle = unbox "dotted"

which generates:

import { type } from "fable-library/Reflection.js";
import { declare } from "fable-library/Types.js";
export const borderStyle = declare(function Test_borderStyle() {});
export function borderStyle$reflection() {
  return type("Test.borderStyle");
}
export function borderStyle$$$$002Ector() {
  return this instanceof borderStyle ? borderStyle.call(this) : new borderStyle();
}

In order to minimize the bundle size, we can remove the constructor.

module Test

type IBorderStyle = interface end

type borderStyle =
    static member inline dotted : IBorderStyle = unbox "dotted"

this generates:

import { type } from "fable-library/Reflection.js";
import { declare } from "fable-library/Types.js";
export const borderStyle = declare(function Test_borderStyle() {});
export function borderStyle$reflection() {
  return type("Test.borderStyle");
}
export const x = "dotted";

We can even go further and have no bundle size increase by using Erase attribute:

module Test

open Fable.Core

type IBorderStyle = interface end

[<Erase>]
type borderStyle =
    static member inline dotted : IBorderStyle = unbox "dotted"

generates ... nothing 😜 🎉

@MangelMaxime
Copy link
Contributor Author

Avoid sprintf for string concatenation because I remember that it's increasing the bundle size as sprintf includes a lot of modules/code. And if we are doing using it just for basic string concatenation it's not worth the drawback I think.

Source

I don't have any measurement for this one but could probably provide one if needed.

@Zaid-Ajaj
Copy link
Owner

Thanks a lot @MangelMaxime for checking this! I will look into it once the before the stable release :)

@Zaid-Ajaj
Copy link
Owner

Implemented!

@MangelMaxime
Copy link
Contributor Author

There are still 3 types not converted yet:

I list them here because I can't create a PR right now.

@Zaid-Ajaj
Copy link
Owner

I keep referencing the wrong issue in my commit messages 😂 but they are implemented and will be available in v0.9

@MangelMaxime
Copy link
Contributor Author

Ah ok sorry, I was looking at master branch which got a new commit since them :)

@Zaid-Ajaj
Copy link
Owner

No I am sorry, I added the commit after reading your message, I meant that I referenced the wrong issue in my commit message 😅 never mind

@MangelMaxime
Copy link
Contributor Author

About sprintf Elmish is already including it source so it's up to you.

I know that we removed from Fulma for increase the bundle size.

Other than that, I don't have more tricks for size optimisation :)

@Zaid-Ajaj
Copy link
Owner

Made another issue for it to continue discussion from there :)

Zaid-Ajaj pushed a commit that referenced this issue Mar 17, 2021
Update to current master
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

No branches or pull requests

2 participants