File tree Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Expand file tree Collapse file tree 3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change 3
3
require "homeland/version"
4
4
require "homeland/plugin"
5
5
6
+ unless ENV [ "RAILS_PRECOMPILE" ]
7
+ # Preload Jieba
8
+ require "homeland/search"
9
+ end
10
+
6
11
module Homeland
7
12
cattr_reader :boot_at
8
13
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ class Search
5
5
attr_accessor :term , :terms
6
6
7
7
INVALID_CHARS = /[:()&!'"]/
8
+ JIEBA = JiebaRb ::Segment . new
8
9
9
10
def initialize ( term )
10
11
term = term . to_s . squish . gsub ( INVALID_CHARS , "" )
@@ -24,9 +25,7 @@ def query_results
24
25
25
26
class << self
26
27
def jieba
27
- return @jieba if defined? @jieba
28
-
29
- @jieba = JiebaRb ::Segment . new
28
+ JIEBA
30
29
end
31
30
end
32
31
Original file line number Diff line number Diff line change
1
+ task memory : :environment do
2
+ require "homeland"
3
+ include ApplicationHelper
4
+ include ActionView ::Helpers ::OutputSafetyHelper
5
+ include ActionView ::Helpers ::TextHelper
6
+
7
+ str = Homeland ::Markdown . example
8
+
9
+ a = [ ]
10
+
11
+ puts "Starting to profile memory..."
12
+ b = { }
13
+ puts "Before =>"
14
+ print_memory
15
+
16
+ count = 5_000_000
17
+ step = ( count / 100 ) . to_i
18
+ count . times do |i |
19
+ sanitize_markdown ( Homeland ::Markdown . call ( str ) )
20
+
21
+ if i % step == 0
22
+ print_memory
23
+ end
24
+ end
25
+
26
+ print_memory
27
+ puts GC . start
28
+ puts "After GC"
29
+ print_memory
30
+ end
31
+
32
+ def print_memory
33
+ rss = ( `ps -eo pid,rss | grep #{ Process . pid } | awk '{print $2}'` . to_i / 1024.0 ) . round ( 1 )
34
+ puts "rss: #{ rss } mb live objects #{ GC . stat [ :heap_live_slots ] } "
35
+ end
You can’t perform that action at this time.
0 commit comments