Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

(perf): minor optimization on attributes extraction #247

Merged
merged 4 commits into from
Aug 11, 2018
Merged

Conversation

vigneshshanmugam
Copy link
Collaborator

@vigneshshanmugam vigneshshanmugam commented Aug 10, 2018

small optimisation on fragment attributes computation

  • attributes object shape is fixed to minimal set of keys
  • pipe attributes computation is done once instead of multiple times.

Before

Stat         Avg     Stdev  Max
Latency (ms) 435.94  107.18 984.88
Req/Sec      224.9   47.2   278
Bytes/Sec    2.93 MB 621 kB 3.64 MB

After

Stat         Avg     Stdev  Max
Latency (ms) 382.2   93.89  994.23
Req/Sec      257     57.96  315
Bytes/Sec    3.36 MB 768 kB 4.13 MB

@codecov
Copy link

codecov bot commented Aug 10, 2018

Codecov Report

Merging #247 into master will increase coverage by 0.46%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #247      +/-   ##
==========================================
+ Coverage   99.06%   99.53%   +0.46%     
==========================================
  Files          16       16              
  Lines         642      643       +1     
  Branches      117      118       +1     
==========================================
+ Hits          636      640       +4     
+ Misses          6        3       -3
Impacted Files Coverage Δ
lib/filter-headers.js 100% <100%> (ø) ⬆️
lib/fragment.js 100% <100%> (ø) ⬆️
lib/request-handler.js 99.01% <100%> (+0.01%) ⬆️
index.js 95.12% <0%> (+7.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fba46b9...c5e35be. Read the comment docs.

lib/fragment.js Outdated
@@ -24,12 +31,17 @@ const getAttributes = (tag, context) => {
Object.assign(attributes, fragmentCtxt);
}

return Object.assign({}, attributes, {
url: attributes.src,
const { src, async, primary, public: isPublic, timeout } = attributes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why public: isPublic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reserved keyword, changing for async as well.

lib/fragment.js Outdated
@@ -9,6 +9,13 @@ const zlib = require('zlib');
const { globalTracer, Tags } = require('opentracing');
const tracer = globalTracer();

const getValue = value => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function seems misnamed. It's not getting the value, it's doing a kind of extended truthiness-check, isn't it? Maybe better named hasValue?

@mo-gr
Copy link
Contributor

mo-gr commented Aug 10, 2018

👍

@vigneshshanmugam
Copy link
Collaborator Author

@mo-gr Need Github PR approval.

lib/fragment.js Outdated
Object.assign({}, { id: this.index }, tag.attributes)
);
this.pipeAttributes = pipeAttributes(
Object.assign({}, { id: this.index }, tag.attributes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the empty shape is pointless.

lib/fragment.js Outdated
public: this.attributes.public
public: isPublic,
async: isAsync,
id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour for id has changed, default arguments only apply to undefined values. Null or empty string will passthrough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. changing it back

@vigneshshanmugam
Copy link
Collaborator Author

@ruiaraujo Done

@vigneshshanmugam
Copy link
Collaborator Author

👍

1 similar comment
@ruiaraujo
Copy link
Contributor

👍

@ruiaraujo ruiaraujo merged commit d05e816 into master Aug 11, 2018
@ruiaraujo ruiaraujo deleted the perf-0 branch August 11, 2018 08:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants