- Notifications
You must be signed in to change notification settings - Fork310
feat: UseXmlWriter
to serialize TwiML instead of usingXDocument
#669
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
C'mon Twilio folks, this code contribution has been ready to merge on the internal repo and public repo for a long time. The longer you let these things rot, the more conflicts will arise. By not merging this, you're choosing to keep a slower and less memory-efficient version around for no reason. 🔥 🌳 |
✌️ |
Hello@Swimburger! Sincere apologies from my side for missing this one. I would request you to re-open this and I'd be happy to help your contributions get merged. I will be looking at this on priority. Thanks! Since these are auto-generated files, we would need to do similar change in the internal tool as well. I'll check with that as well |
I don't recall whether I created a PR for this internally when I was at Twilio. |
All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.
Currently the TwiML tree is constructed as a tree of objects which are then converted into a tree of objects from the
System.Xml.Linq
, to then be serialized to a string usingXDocument.Save
.This creates three copies of the same data in memory, one as TwiML objects, one as
System.Xml.Linq
objects, and one as a string.To reduce the amount of memory used and increase performance, this PR uses the
XmlWriter
APIs instead ofSystem.Xml.Linq
APIs.The TwiML tree is constructed just the same, but that tree is serialized without creating another copy of the tree, and can be written directly to
Stream
s,TextWriter
s, andXmlWriter
s.If the
Stream
is a file stream, a network stream, etc., the entire XML string wouldn't be loaded into memory as a result.If you do use a
TextWriter
or theToString
method, the string would be loaded in memory but this PR won't create another copy of the tree asSystem.Xml.Linq
objects.The resulting XML uses self-closing tags at the moment, which would reduce the size of the string and make HTTP responses containing TwiML smaller, but this can be reverted if necessary for backwards compatibility reasons.
Checklist