String deduplication optimization plugin?

Hey fellas,

I’ve been using webpack for a few months now, and I had an idea for an optimization plugin. Before I invested a lot of time and energy figuring out how to write it, I wanted to run the idea by you guys to make sure it was sound and hadn’t been attempted (and discarded) before.

Basically, I’m wondering if webpack can construct a global strings hash table, insert all strings that are used above a certain threshold, then replace references to those strings with hash table lookups.

Say webpack generates these lines of code right now (in multiple modules that are eventually output to the same bundle):

var some_var = "some string";
var some_other_var = "some string";
var some_other_other_var = "some string";

Could it instead generate this code:

var strings = { a: "some string" };
var some_var = strings.a
var some_other_var = strings.a
var some_other_other_var = strings.a

Hoisting all strings seems like it wouldn’t be wise, so I was planning on configuration options for frequency and length to determine what strings were hoisted to the lookup table.

So my questions before I dive in and get to work on something:

  1. Is this possible with the API webpack exposes to plugins?
  2. Has this been attempted and rejected before?

Thanks in advance!

Author: Fantashit

1 thought on “String deduplication optimization plugin?

Comments are closed.