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

(Coachmark): Test performance of anonymous render functions within when directive #3723

Closed
1 task done
najikahalsema opened this issue Oct 16, 2023 · 3 comments · Fixed by #3639
Closed
1 task done

Comments

@najikahalsema
Copy link
Collaborator

Code of conduct

  • I agree to follow this project's code of conduct.

Description of issue

(To be done once the initial component is merged to main)

The when directive takes anonymous functions as arguments. The question is whether there's a performance difference between using anonymous methods as arguments or initialising these render methods as anonymous. We should experiment with the two and test the performance of each to see if there's any noticeable difference.

For example,

Wrapping these render methods in an anonymous function within the parameters of when

  method1() {
    return html`
      ${this.name} is my name too   
    `;
  }

// ....

  render() {
    return html`
      ${when(this.name, () => this.method1(), () => this.method2())}
    `;
    }  

vs using an anonymous function from the get-go:

  method1 = () => {
    return html`
      ${this.name} is my name too   
    `;
  }

// ... 

  render() {
    return html`
      ${when(this.name, this.method1, this.method2)}
    `;
    }  
@Rajdeepc
Copy link
Contributor

Rajdeepc commented Nov 7, 2023

@najikahalsema While there is not a significant amount of time difference between the two usage of function expressions, anonymous function takes a little bit more time than regular function declaration.

Tested using the console.time() and console.timeEnd() methods

  method1() {
    return html`
      ${this.name} is my name too   
    `;
  }

// ....

  render() {
    return html`
      ${when(this.name, () => this.method1(), () => this.method2())}
    `;
    }  

Performance with console.time

Image

using an anonymous function from the get-go:

  method1 = () => {
    return html`
      ${this.name} is my name too   
    `;
  }

// ... 

  render() {
    return html`
      ${when(this.name, this.method1, this.method2)}
    `;
    }  

Image

@Rajdeepc Rajdeepc self-assigned this Nov 7, 2023
@najikahalsema
Copy link
Collaborator Author

Interesting. thank you so much for taking a look! I think the second one is better based on it's nearly half the amount of time needed to render.

@Rajdeepc
Copy link
Contributor

Cool Thanks! Feel free to close this issue once Coachmark is merged.
Tagging the PR here: #3639

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants