Skip to content

Commit 03a7d4f

Browse files
committed
Finalize Kevin's handrolled parser.
And get rid of the Ragel parser. This is 7% faster on activitypub, 15% after on twitter and 11% faster on citm_catalog. There might be some more optimization opportunities, I did a quick optimization pass to fix a regression in string parsing, but other than that I haven't dug much in performance.
1 parent 5694cff commit 03a7d4f

File tree

5 files changed

+1372
-1614
lines changed

5 files changed

+1372
-1614
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
ext/json/ext/parser/parser.c linguist-generated=true
21
java/src/json/ext/Parser.java linguist-generated=true

Rakefile

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ end rescue nil
3333
EXT_ROOT_DIR = 'ext/json/ext'
3434
EXT_PARSER_DIR = "#{EXT_ROOT_DIR}/parser"
3535
EXT_PARSER_DL = "#{EXT_PARSER_DIR}/parser.#{CONFIG['DLEXT']}"
36-
RAGEL_PATH = "#{EXT_PARSER_DIR}/parser.rl"
3736
EXT_PARSER_SRC = "#{EXT_PARSER_DIR}/parser.c"
3837
EXT_GENERATOR_DIR = "#{EXT_ROOT_DIR}/generator"
3938
EXT_GENERATOR_DL = "#{EXT_GENERATOR_DIR}/generator.#{CONFIG['DLEXT']}"
@@ -234,53 +233,6 @@ else
234233
system 'ctags', *Dir['**/*.{rb,c,h,java}']
235234
end
236235

237-
file EXT_PARSER_SRC => RAGEL_PATH do
238-
cd EXT_PARSER_DIR do
239-
if RAGEL_CODEGEN == 'ragel'
240-
sh "ragel parser.rl -G2 -o parser.c"
241-
else
242-
sh "ragel -x parser.rl | #{RAGEL_CODEGEN} -G2"
243-
end
244-
src = File.read("parser.c").gsub(/[ \t]+$/, '')
245-
src.gsub!(/^static const int (JSON_.*=.*);$/, 'enum {\1};')
246-
src.gsub!(/^(static const char) (_JSON(?:_\w+)?_nfa_\w+)(?=\[\] =)/, '\1 MAYBE_UNUSED(\2)')
247-
src.gsub!(/0 <= ([\( ]+\*[\( ]*p\)+) && \1 <= 31/, "0 <= (signed char)(*(p)) && (*(p)) <= 31")
248-
src[0, 0] = "/* This file is automatically generated from parser.rl by using ragel */"
249-
File.open("parser.c", "w") {|f| f.print src}
250-
end
251-
end
252-
253-
desc "Generate diagrams of ragel parser (ps)"
254-
task :ragel_dot_ps do
255-
root = 'diagrams'
256-
specs = []
257-
File.new(RAGEL_PATH).grep(/^\s*machine\s*(\S+);\s*$/) { specs << $1 }
258-
for s in specs
259-
if RAGEL_DOTGEN == 'ragel'
260-
sh "ragel #{RAGEL_PATH} -S#{s} -p -V | dot -Tps -o#{root}/#{s}.ps"
261-
else
262-
sh "ragel -x #{RAGEL_PATH} -S#{s} | #{RAGEL_DOTGEN} -p|dot -Tps -o#{root}/#{s}.ps"
263-
end
264-
end
265-
end
266-
267-
desc "Generate diagrams of ragel parser (png)"
268-
task :ragel_dot_png do
269-
root = 'diagrams'
270-
specs = []
271-
File.new(RAGEL_PATH).grep(/^\s*machine\s*(\S+);\s*$/) { specs << $1 }
272-
for s in specs
273-
if RAGEL_DOTGEN == 'ragel'
274-
sh "ragel #{RAGEL_PATH} -S#{s} -p -V | dot -Tpng -o#{root}/#{s}.png"
275-
else
276-
sh "ragel -x #{RAGEL_PATH} -S#{s} | #{RAGEL_DOTGEN} -p|dot -Tpng -o#{root}/#{s}.png"
277-
end
278-
end
279-
end
280-
281-
desc "Generate diagrams of ragel parser"
282-
task :ragel_dot => [ :ragel_dot_png, :ragel_dot_ps ]
283-
284236
desc "Create the gem packages"
285237
task :package do
286238
sh "gem build json.gemspec"

0 commit comments

Comments
 (0)