cssinjs / istf-spec

Interoperable Style Transfer Format [DRAFT]
247 stars 8 forks source link

Optimization: use single array #19

Open kof opened 7 years ago

kof commented 7 years ago

Should we go for single array? As consequence we will only be able to express this:

  1. [MARKER]
  2. [MARKER, value]

Right now it seems to work nicely.

[
  [RULE_START, 1],
    [SELECTOR, 'body'],
    [PROPERTY, 'color'],
    [VALUE, 'red'],
  [RULE_END]
]

will become

[
  RULE_START, 1,
    SELECTOR, 'body',
    PROPERTY, 'color',
    VALUE, 'red',
  RULE_END
]
kof commented 7 years ago

Should we also go for all string values? Benchmark shows a considerable perf benefit in v8, if it is not flowed: https://esbench.com/bench/592d599e99634800a03483d8

[
  1, 1,
    2, 'body',
    3, 'color',
    4, 'red',
  5
]

will become

[
  '1', '1',
    '2', 'body',
    '3', 'color',
    '4', 'red',
  '5'
]
  1. I am not sure if its worth it from the performance perspective (because only v8 and on micro level)
  2. Tested storage savings, using 100kb probe it shrinks down to 80kb => 20%, not sure if its worth. Probe was [1,1,2,"body",3,"color",4,"red",5] => 1\n1\n\n2\n\nbody\n\n3\n\ncolor\n4\nred\n5
  3. We will need a separate array for fn refs or any other refs