Changeset 925

Show
Ignore:
Timestamp:
12/14/06 21:10:48 (2 years ago)
Author:
ahu
Message:

first of the speedup patches. move labelmap to an unsorted vector, and hope memory coherence and lack of allocations wins out over a map
also, do not do whole compression thing for first answer, if identical to question - blindly copy in '0xc00c'

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pdns/pdns/dnswriter.cc

    r803 r925  
    4242 
    4343  d_stuff=0xffff; 
     44  d_labelmap.reserve(16); 
    4445} 
    4546 
     
    6465  d_rollbackmarker=d_content.size(); 
    6566 
    66   xfrLabel(d_recordqname, true); 
    67   d_content.insert(d_content.end(), d_record.begin(), d_record.end()); 
    68   d_record.clear(); 
    69  
     67  if(d_qname == d_recordqname) {  // don't do the whole label compression thing if we *know* we can get away with "see question" 
     68    static char marker[2]={0xc0, 0x0c}; 
     69    d_content.insert(d_content.end(), &marker[0], &marker[2]); 
     70  } 
     71  else { 
     72    xfrLabel(d_recordqname, true); 
     73    d_content.insert(d_content.end(), d_record.begin(), d_record.end()); 
     74    d_record.clear(); 
     75  } 
     76       
    7077  d_stuff = sizeof(dnsrecordheader); // this is needed to get compressed label offsets right, the dnsrecordheader will be interspersed 
    7178  d_sor=d_content.size() + d_stuff; // start of real record  
     
    115122} 
    116123 
    117 // this is the absolute hottest function in the pdns recursor 
     124DNSPacketWriter::lmap_t::iterator find(DNSPacketWriter::lmap_t& lmap, const string& label) 
     125
     126  DNSPacketWriter::lmap_t::iterator ret; 
     127  for(ret=lmap.begin(); ret != lmap.end(); ++ret) 
     128    if(ret->first == label) 
     129      break; 
     130  return ret; 
     131
     132 
     133// this is the absolute hottest function in the pdns recursor  
    118134void DNSPacketWriter::xfrLabel(const string& label, bool compress) 
    119135{ 
     
    128144  for(parts_t::const_iterator i=parts.begin(); i!=parts.end(); ++i) { 
    129145    //    cerr<<"chopped: '"<<chopped<<"'\n"; 
    130     map<string, uint16_t>::iterator li=d_labelmap.end(); 
     146    lmap_t::iterator li=d_labelmap.end(); 
    131147    // see if we've written out this domain before 
    132     if(compress && (li=d_labelmap.find(chopped))!=d_labelmap.end()) {    
     148    if(compress && (li=find(d_labelmap, chopped))!=d_labelmap.end()) {    
    133149      uint16_t offset=li->second; 
    134150      offset|=0xc000; 
     
    139155 
    140156    if(li==d_labelmap.end() && pos< 16384) 
    141       d_labelmap[chopped]=pos;                       //  if untrue, we need to count - also, don't store offsets > 16384, won't work 
    142      
     157      d_labelmap.push_back(make_pair(chopped, pos));                       //  if untrue, we need to count - also, don't store offsets > 16384, won't work 
     158 
    143159    d_record.push_back((char)(i->second - i->first)); 
    144160    unsigned int len=d_record.size(); 
     
    147163    //    cerr<<"Added: '"<<string(label.c_str() + i->first, i->second - i->first) <<"'\n"; 
    148164    pos+=(i->second - i->first)+1; 
    149     chopOff(chopped);                   // www.powerdns.com. -> powerdns.com. -> com. -> . 
     165 
     166    if(i+1 != parts.end()) 
     167      chopOff(chopped);                   // www.powerdns.com. -> powerdns.com. -> com. -> . 
    150168  } 
    151169  d_record.push_back(0); 
  • trunk/pdns/pdns/dnswriter.hh

    r802 r925  
    4141class DNSPacketWriter 
    4242{ 
     43 
    4344public: 
     45  typedef vector<pair<string, uint16_t> > lmap_t; 
    4446  enum Place {ANSWER=1, AUTHORITY=2, ADDITIONAL=3};  
    4547 
     
    99101  uint16_t d_recordqtype, d_recordqclass; 
    100102  uint32_t d_recordttl; 
    101   map<string, uint16_t> d_labelmap; 
     103  lmap_t d_labelmap; 
    102104  uint16_t d_stuff; 
    103105  uint16_t d_sor;