Clean HTML stuff, add Timeline.WriteHTMLTo - #42
Open
arl wants to merge 3 commits into
Open
Conversation
Fixes jamiealquiza#32 `Timeline.WriteHTMLTo` takes a `io.Writer` so that it can directly be used in various cases, for example directly passing an http.ResponseWriter. Using a writer, many allocations are removed by directly formatting the output with `fmt.Fprint`, remove the `bytes.Buffer. as well. Use a `text/template` for HTML generation. An `html/template` are very similar but escapes the strings, and it was not playing well the JSON marshaling of graph labels, also it is not based on user input so no risk of code injection. `genGraphHTML` also takes a writer to eliminate more copies. Modify `Timeline.WriteHTML` to keep backward compatibility but make it use WriteHTMLTo under the hood. Add `BenchmarkWriteHTMLTo`. In the following benchmarks, `old` is a version of `WriteHTMLTo` equivalent to original `WriteHTML` code, present in current master, whereas `new` is this commit. name old time/op new time/op delta WriteHTMLTo-8 25.4µs ±12% 7.0µs ± 3% -72.49% (p=0.008 n=5+5) name old alloc/op new alloc/op delta WriteHTMLTo-8 161kB ± 0% 1kB ± 0% -99.37% (p=0.008 n=5+5) name old allocs/op new allocs/op delta WriteHTMLTo-8 56.0 ± 0% 50.0 ± 0% -10.71% (p=0.008 n=5+5)
`Timeline.WriteHTML` panicked if no metrics have been added via `AddTime`. Fix this and add a test to verify new behaviour.
Owner
|
Hi, apologies, I just now noticed these pull requests today (github notifications aren't the best). I'll review these shortly! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #32
Timeline.WriteHTMLTotakes aio.Writerso that it can directlybe used in various cases, for example directly passing an
http.ResponseWriter. Using a writer, many allocations are removed
by directly formatting the output with
fmt.Fprint, remove the`bytes.Buffer. as well.
Use a
text/templatefor HTML generation. Anhtml/templatearevery similar but escapes the strings, and it was not playing
well the JSON marshaling of graph labels, also it is not based on
user input so no risk of code injection.
genGraphHTMLalso takes a writer to eliminate more copies.Modify
Timeline.WriteHTMLto keep backward compatibility butmake it use WriteHTMLTo under the hood.
Add
BenchmarkWriteHTMLTo. In the following benchmarks,oldisa version of
WriteHTMLToequivalent to originalWriteHTMLcode, present in current master, whereas
newis this commit.