Better HN
topnewbestaskshowjobs
Log inSign up

mightee_pirate

2 karma · joined Apr 20, 2023 (3y ago) · 2 submissions

Submissions

comment 2y ago · link · parent

thx

comment 2y ago · link · parent

I am very interested in parsing and optimizing them. Currently I have an html parser written in go. I have used Go's html parser but it is waaay slower than mine. Here what I do: - stream the content (either from a file or from network) and send chunks to the tokenizer

- tokenizer is dead simple with a state machine

- when an html tag is found, emit the token with positions (problem is someone needs to hold the whole incoming buffer. currently its copying the incoming bytes but I plan to hold the bytes until a token is found. after emitting the token with the buffer (copying) the inner buffer will be freed)

- parser does its thing and creates a DOM

as you can see I am not well versed in optimizing to the last bit but I am very interested in diving deep into the optimizations.

Currently I am looking at zero-copy networking. there is supposedly a library for go (fasthttp) that would not copy bytes from networking interface but I havent tried it yet.

What kind of algorithms would you recommend for tokenizing & parsing html / xml very efficiently ?