This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [libstdc++ PATCH/RFC] Aggressive space optimization for std::vector

Doug Gregor <> writes:

| There is more that can be done on the micro-optimization level, such
| as eliminating some of the extra overhead in _Vector_impl (e.g., its
| iterators can just be pointers, because they will never be exposed to
| the user). However, I'd like to know if this type of optimization is
| desired in libstdc++. It uglifies the source a bit, but it can be a
| boon to users.

I guess this space optimization may have some impact on code
efficiency (optimization for something else than space).  Did you make
any measurements? I'm worried because GCC currently tends not to
inline even simple accessor -- see past report by Benjamin.  Try to
compile with -Winline.

It would be nice if this code was rather controlled by -Os.

Also, I suppose this

!   // Primary template has maximum alignment
!   template<std::size_t _Alignment>
!     struct _Type_with_alignment 
!     { struct __attribute__((__aligned__)) _M_type {}; };
! #define _GLIBCXX_TYPE_WITH_ALIGNMENT(_Align)				\
!   template<>								\
!     struct _Type_with_alignment<_Align> \
!     { struct __attribute__((__aligned__(_Align))) _M_type {}; }

is for getting around the bug in how attributes are handled (I filled
a bug report on that a while ago), i.e. attributes don't respect usual
name lookup rules.  Please add a note to that effect.

Also, I would rather see

! template<std::size_t _Size, std::size_t _Alignment>
!   struct __type_traits<std::_Basic_pod<_Size, _Alignment> >
!   {
!     typedef __true_type    has_trivial_default_constructor;
!     typedef __true_type    has_trivial_copy_constructor;
!     typedef __true_type    has_trivial_assignment_operator;
!     typedef __true_type    has_trivial_destructor;
!     typedef __true_type    is_POD_type;
!   };
in the file where the original __type_traits<> is defined.  In the
long run, we should move away from the type based __true_type usage
toward integral constant usage.

+       // iterators
+       iterator
+       begin() { return iterator (this->_M_start); }

no space.

+       void     
+       swap(_Vector_impl& __x)
+       {
+ 	std::swap(this->_M_start, __x._M_start);
+ 	std::swap(this->_M_finish, __x._M_finish);
+ 	std::swap(this->_M_end_of_storage, __x._M_end_of_storage);
+       }

be careful about indentation.

!       template <class _InputIterator>
! 	void 
! 	assign(_InputIterator __first, _InputIterator __last)

same here.

-- Gaby

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]