변경 가능한 상태를 사용할 때보다 불변성을 사용할 때 실행 속도가 실제로 빨라질 수도 있다는
데 불변성의 모순이 있다. 객체의 상태를 변경할 수 없다면, 상태를 변경하고 싶은 경우에는 복
사를 하는 수밖에 없다. 다행히 함수형 데이터 구조
functional
data
structure
는 두 복사본 사이에 변화
가 없는 부분을 공유하는 방식을 사용해서 복사에 드는 부가 비용을 최소화한다.
반면 객체지향 언어에서 사용하는 데이터 구조에서는 효율적인 복사를 지원하지 않는 경우가
자주 있다. 방어적인 고객은 데이터 구조에 저장한 내부 상태를 공유할 필요가 있을 때, 원치 않
는 변경으로 인해 데이터가 오염되는 위험을 막기 위해 전체 변경 가능한 데이터 구조를 복사하
는 비싼 대가를 치러야 한다.
잠재적으로 성능 향상을 얻을 수 있는 다른 방법으로, 스칼라의
Stream
(
http
://
bit
.
ly
/
1toy0G5
)
타입과 같이 지연 계산
lazy
evaluation
을 지원하는 데이터 구조를 사용할 수도 있다. 하스켈 같은 일
부 함수형 언어는 지연 계산이 기본이다. 이는 해답이 필요할 때까지 계산을 미뤄둔다는 의미다.
1
스칼라는 기본적으로 미리 계산
eager
evaluation
(엄격한 계산
strict
evaluation
이라고도 함)을
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.