dwyl / dwyl/hits

Perf Optimisation: Use EEX Template for SVG Rendering

Open
#70 1 comment 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
Elixir
Stars
451
Forks
63
Avg merge
1d 8h
Merged PRs (30d)
1

Description

At present we have a 511 Byte [`template.svg`](https://github.com/dwyl/hits-elixir/blob/master/lib/template.svg) file which we are _manually_ [`String.replace`](https://github.com/dwyl/hits-elixir/blob/12e7f9a9f84d9341c022320587da29b88b7f940e/lib/hits.ex#L30)-ing the `{count}` in:

```
String.replace(svg_badge_template(), ~r/{count}/, to_string(count))
```

This does not take advantage of Phoenix's template compilation for faster rendering.

# Todo

+ [ ] refactor template to `badge.svg.eex`
+ [ ] render using `render(conn, "badge.svg", count)`
+ [ ] apply gzip compression for even faster rendering

> _**Note**: rendering is **not** currently a "bottleneck" in the app,
the DB query is orders of magnitude slower than `String.replace`.
This optimisation should be considered `after` ETS is implemented for caching the count._

Contributor guide

Open the contributing guide

Research direction

Start with lib/hits.ex at line 30 and lib/template.svg, then compare the current String.replace path with the proposed badge.svg.eex rendering. Check how the count reaches the SVG response and how gzip would fit after ETS caching. Done means the compiled template renders the same badge and the requested compression is applied without changing the count output.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
backend, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.