question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tree-shaking ready API

See original GitHub issue

Right now library exports one big class with everything inside.

It is bad for website performance because webapp JS bundle will contain all methods of Color.js even if user use only a few of them.

Modern JS bundler has tree-shaking feature. If you will move rare (or all) methods to separated functions with separated export, JS bundler will keep only used functions in the JS bundle.

I am talking about something like:

import { contrast } from 'colorjs.io'

contrast(color)

I understand that this feature requires a full refactoring and will not be implemented soon. Just an idea for better web performance.

Color spaces could be tree-shaked as well. Here is an example from culori.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
LeaVeroucommented, Jun 28, 2022

I mean that OOP is forcing to bloat JS bundle size by adding unnecessary functions to website JS file.

Even if it’s not tree-shakeable, it’s still modular, as in, you can import only the modules you need. Don’t forget that not all users use bundlers.

I think OOP has the same runtime performance.

OOP does not have the same runtime performance at all. I wish it did! When I switched the API locally to use object literals instead of Color instances the performance increase was huge (my benchmark went from 1400ms to 750ms!). There was literally no other change, just not creating Color instances and passing object literals around instead was that much faster.

0reactions
aicommented, Jun 27, 2022

Just to clarify. For bad web perfomance I mean that OOP is forcing to bloat JS bundle size by adding unnecessary functions to website JS file.

I think OOP has the same runtime performance. This issue is addressing loading performance and my dream to have less JS on modern websites.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tree Shaking - webpack
Tree shaking is a term commonly used in the JavaScript context for dead-code elimination. It relies on the static structure of ES2015 module...
Read more >
Performance Tests | ReadyAPI Documentation
Create and run automated functional, load and security tests for REST and SOAP APIs. Virtualize APIs and run the mocks.
Read more >
Build a Tree-Shaking Utility in JavaScript | by Chidume Nnamdi
Bringing it to programming, tree-shaking involves removing dead code. Dead code is code that is declared but not used. Here are a few...
Read more >
Untitled
Gurbilas patshahi 10, Gambar origami kupu-kupu, Poison dart tree frog care, Fandrop reddit, ... Lvl 50 barbarian skill build pve, Ready api free...
Read more >
lbY - ALBA.Net
Emilio badiola zapateria, Ready api maven, Dodge fitness center front desk, Wnbull, ... Antoni forrellad 101, Coral tree bonsai care, Boys girls zico, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found