Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor stencil.merger namespace #152

Merged
merged 28 commits into from
Jul 26, 2024
Merged

refactor stencil.merger namespace #152

merged 28 commits into from
Jul 26, 2024

Conversation

erdos
Copy link
Owner

@erdos erdos commented Nov 3, 2023

Rework and simplify merger.clj file. This namespace is responsible for extracting stencil expressions from the template files while maintaining a correct XML tree.

The file is the oldest part of the library (from 2018) and even though we barely had to touch it, it still shows signs of immaturity: complex code, bad naming, hard to follow test cases, missing docs, not very good performance.

The plan is to rewrite it to utilize transducers more with a trampoline-style executor around it. The principles of the rewrite are going to be the following:

  • Simplify code by breaking it up to smaller methods and create an easy-to-follow pattern to be used around the whole file (with the trampoline style)
  • Write comments for cases that are not obvious
  • Get to almost 100% test coverage on merging algorithm
  • Do some benchmarking to make sure there is no visible performance degradation.

@erdos erdos changed the title wip simplify stencil.merger namespace Nov 3, 2023
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (master@fc2cfbd). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #152   +/-   ##
=========================================
  Coverage          ?   93.78%           
=========================================
  Files             ?       30           
  Lines             ?     2077           
  Branches          ?       92           
=========================================
  Hits              ?     1948           
  Misses            ?       37           
  Partials          ?       92           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@erdos erdos force-pushed the master branch 3 times, most recently from 2f5ea5f to a1a8cbb Compare November 19, 2023 12:56
@erdos erdos force-pushed the master branch 2 times, most recently from 68c7242 to ed46cf8 Compare July 22, 2024 16:27
@erdos
Copy link
Owner Author

erdos commented Jul 26, 2024

Performance testing with document from issue #81

(comment
  ;; clj -A:build
  (require '[clojure.repl.deps :refer [add-lib]])
  (add-lib 'criterium/criterium {:mvn/version "0.4.6"}) 
  (use 'criterium.core)
  (require 'stencil.merger)

  (->> "/home/erdos/Downloads/word/document.xml"
       (clojure.java.io/file)
       (clojure.java.io/reader)
       (stencil.merger/parse-to-tokens-seq)
       (dorun)
       (bench))
  )

Output on current branch:

Evaluation count : 240 in 60 samples of 4 calls.
             Execution time mean : 305.535731 ms
    Execution time std-deviation : 31.925299 ms
   Execution time lower quantile : 293.731132 ms ( 2.5%)
   Execution time upper quantile : 348.607057 ms (97.5%)
                   Overhead used : 5.464008 ns

Found 5 outliers in 60 samples (8.3333 %)
	low-severe	1 (1.6667 %)
	low-mild	4 (6.6667 %)
 Variance from outliers : 72.0506 % Variance is severely inflated by outliers

Baseline on master branch:

Evaluation count : 60 in 60 samples of 1 calls.
             Execution time mean : 1.526966 sec
    Execution time std-deviation : 50.359723 ms
   Execution time lower quantile : 1.480701 sec ( 2.5%)
   Execution time upper quantile : 1.655090 sec (97.5%)
                   Overhead used : 5.454800 ns

Found 4 outliers in 60 samples (6.6667 %)
	low-severe	2 (3.3333 %)
	low-mild	2 (3.3333 %)
 Variance from outliers : 19.0423 % Variance is moderately inflated by outliers

To summarize, there is a significant (5X) speedup. Std-deviance increased, possibly due to the GC kicking in because of the higher memory usage by the larger number of tests in a unit of time.

@erdos erdos changed the title simplify stencil.merger namespace rewrite stencil.merger namespace Jul 26, 2024
@erdos erdos changed the title rewrite stencil.merger namespace refactor stencil.merger namespace Jul 26, 2024
@erdos erdos marked this pull request as ready for review July 26, 2024 12:31
@erdos erdos merged commit fc3ce48 into master Jul 26, 2024
6 checks passed
@erdos erdos deleted the simplify-merger branch July 26, 2024 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant