faster web templates lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Blestan · 2012-05-03 08:02 HI All! After several test and analysis i found that the current implementation of the templates is not very productive ... the main issue is that the template file is read and parsed/evaluated  on every request processing. my idea is to read the template files only once (or on file date/time change) .. then make some sort of compiling: read the file (maybe memory mapped files will be a good alternative to traditional stream i/o) find all "tag free" regions in the file and keep a "pointer" to them find all tags and build a list find all params and assign them to the tag on request processing get all tags/params values and build a result string by concatenation of all "static"parts + "variable" parts; a better string builder is also a needed ( to avoid multiple memory reallocs by setlength function) if some body have similar ideas i will be happy to start a project and then submit a patch regards, blestan ---------------------------------------------------------------------- Leledumbo · 2012-05-03 13:50 Quoteread the file (maybe memory mapped files will be a good alternative to traditional stream i/o)Hmm... wouldn't this increase the memory usage? Anyway, the template handling is not that slow, though there are rooms for improvement. I'd rather suggest changing the callback mechanism to something like (already done in one of my projects, but build on top of existing callback mechanism, so it's actually slower though a bit better IMO. Could be faster if really implemented): Code: [Select]MyTemplate := TFPTemplate.Create('template/main.tpl'); Tag := MyTemplate['Name']; // this takes pointer to template named 'Name' Tag.Value := 'My Name'; // this fills the template replacement Tag := MyTemplate['Birthdate']; BirthdateFormat := Tag['Format']; // this takes template argument named 'Format' Tag.Value := FormatDateTime(MyBirthdate,BirthdateFormat); Response.Content := MyTemplate.GetContent; // this builds the final string